久久久久久久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?)
主站蜘蛛池模板: 欧美女优在线观看 | 18gay男同69亚洲网站 | 亚洲欧美精品 | 成人影院一区二区三区 | 午夜影晥| 久久久久国产成人精品亚洲午夜 | 草比av| 99久久99久久精品国产片果冰 | 亚洲第1页| 亚洲一区二区中文字幕 | 国产真实精品久久二三区 | 日韩在线精品视频 | 久久久久久免费毛片精品 | 99精品免费久久久久久久久日本 | 欧美色综合一区二区三区 | 亚洲精品欧美一区二区三区 | 亚洲第一网站 | 日韩在线国产 | 精品久久久久久久久久久 | 99久久精品国产一区二区三区 | 精产国产伦理一二三区 | 日韩在线综合 | 国产精品一区二区在线播放 | 亚洲视频中文字幕 | 日韩中文字幕在线观看视频 | 欧美国产日韩一区二区三区 | 久久久www成人免费精品 | 91在线看 | 97超碰在线免费 | 精品国产亚洲一区二区三区大结局 | www.久草.com| 亚洲成人av一区二区 | 国产精品福利网站 | 日韩中文字幕在线观看 | wwwww在线观看 | 国产 欧美 日韩 一区 | 久久国产欧美一区二区三区精品 | 欧美一区二区三区在线 | h视频在线免费看 | 亚洲不卡 | 中文字幕在线二区 |