久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將項(xiàng)目綁定到 MenuItem ->使用命令

Bind Items to MenuItem -gt; use Command(將項(xiàng)目綁定到 MenuItem -使用命令)
本文介紹了將項(xiàng)目綁定到 MenuItem ->使用命令的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我有一個(gè) MenuItem,其中包含一組項(xiàng)目.它看起來(lái)像文件 -> 打開(kāi)菜單項(xiàng).

I have a MenuItem, which has a collection of items in it. It looks like the File -> Open Menuitem.

所以:

  • 文件
    • 打開(kāi)
      • 從數(shù)據(jù)庫(kù)打開(kāi)
        • 文件 1
        • 文件 2
        • 文件 3

        XAML 代碼:

        <Menu>
        <MenuItem Header="File">
            <MenuItem Header="Open">
                <MenuItem Header="From Database" ItemsSource="{Binding OCFragebogen}"/>
            </MenuItem>
        </MenuItem>
        </Menu>
        

        我想在單擊特定項(xiàng)目時(shí)調(diào)用命令.示例:用戶單擊文件 1,應(yīng)調(diào)用命令,其中文件 1"是命令參數(shù).

        I want to call a Command, when a specific item has been clicked. Example: User clicks on File 1, a command should be called where the "File 1" is the Command Parameter.

        ViewModel 包含我想在 MenuItem集合"中顯示的項(xiàng)目

        ViewModel contains the Items, which I want to display in the MenuItem "collection"

        private ObservableCollection<string> _OCFragebogen;
        public ObservableCollection<string> OCFragebogen
        {
            get
            {
                if (_OCFragebogen == null)
                    _OCFragebogen = new ObservableCollection<string>();
                return _OCFragebogen;
            }
            set
            {
                _OCFragebogen = value;
                RaisePropertyChanged(() => OCFragebogen);
            }
        }
        

        明確地說(shuō):當(dāng)用戶點(diǎn)擊 MenuItem 中的一個(gè)項(xiàng)目(來(lái)自 ItemsSource)時(shí),應(yīng)該調(diào)用一個(gè)命令,我想對(duì)點(diǎn)擊的項(xiàng)目執(zhí)行某些操作.

        To make it clear: When the user clicks on an item (from the ItemsSource) in the MenuItem, a Command should be called where I want to do something with the clicked Item.

        我必須在哪里使用命令來(lái)調(diào)用 ViewModel 中的方法 (RelayCommand)?我希望在單擊 ItemsSource 中的一個(gè)項(xiàng)目時(shí)使用它 + 我想將單擊的項(xiàng)目傳遞給該方法.

        Where do I have to use the command to call a method (RelayCommand) in my ViewModel? I want it to be used when an Item from the ItemsSource has been clicked + I want to pass the clicked item to the method.

        推薦答案

        這應(yīng)該對(duì)你有用

        <MenuItem Header="From Database" 
                  ItemsSource="{Binding YourItemSource}">
            <MenuItem.ItemContainerStyle>
                <Style TargetType="MenuItem">
                    <Setter Property="Command" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuItem}, Path=DataContext.YourCommandName}"></Setter>
                    <Setter Property="CommandParameter" Value="{Binding}"></Setter>
                 </Style>
             </MenuItem.ItemContainerStyle>
        </MenuItem>
        

        這篇關(guān)于將項(xiàng)目綁定到 MenuItem ->使用命令的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

        【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

LINQ to SQL and Concurrency Issues(LINQ to SQL 和并發(fā)問(wèn)題)
Yield return from a try/catch block(try/catch 塊的收益回報(bào))
Should I call Parameters.Clear when reusing a SqlCommand with a transation?(重用帶有事務(wù)的 SqlCommand 時(shí),我應(yīng)該調(diào)用 Parameters.Clear 嗎?)
what does a using statement without variable do when disposing?(處理時(shí)不帶變量的 using 語(yǔ)句有什么作用?)
Why doesn#39;t TransactionScope work with Entity Framework?(為什么 TransactionScope 不適用于實(shí)體框架?)
How to dispose TransactionScope in cancelable async/await?(如何在可取消的 async/await 中處理 TransactionScope?)
主站蜘蛛池模板: av日韩一区 | 91精品国产欧美一区二区成人 | 久久国产视频播放 | 国产精品成人一区二区三区 | 午夜免费在线观看 | 一区二区三区在线免费 | 国产乱肥老妇国产一区二 | 欧美一级片免费看 | 91精品国产色综合久久不卡98 | 成人综合伊人 | 国产精品视频网站 | 亚洲精品性视频 | 午夜视频一区二区三区 | 久久国产一区 | 女同久久另类99精品国产 | 夜夜草天天草 | 亚洲久在线 | 亚洲欧美一区二区三区国产精品 | 欧美日韩视频在线 | 午夜精品在线观看 | 国内自拍偷拍一区 | 国产亚洲精品综合一区 | 91av在线影院 | 伊人久操| 中文字幕一区二区三区在线观看 | 国产女人与拘做视频免费 | 国产精品久久久久久久久久 | 日韩在线一区二区 | 天天干人人 | 伊人久久精品一区二区三区 | 日韩视频在线观看一区二区 | 久久久国产精品入口麻豆 | 欧美综合一区二区三区 | 成人免费观看男女羞羞视频 | 久久久久国产 | 在线欧美小视频 | 一级特黄在线 | 国产精品福利网站 | 蜜臀久久 | 国产三级在线观看播放 | 亚洲电影中文字幕 |