第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

帶有按鈕列的 WPF MVVM 網(wǎng)格

帶有按鈕列的 WPF MVVM 網(wǎng)格

C#
回首憶惘然 2021-12-25 16:45:36
我正在遵循 MVVM 模式。我有一個(gè)包含幾列的網(wǎng)格,其中一列包含 Button。單擊按鈕我想打開對(duì)話框,該對(duì)話框?qū)@示與單擊按鈕的特定行相關(guān)的數(shù)據(jù)。但問題在于綁定,因?yàn)槲覠o法將控件與視圖模型綁定。<Button  Command="{Binding Path=ParentRow.DataContext,          RelativeSource={RelativeSource AncestorType={x:Type UserControl}},         UpdateSourceTrigger=PropertyChanged, Mode=Default}"          lib:Event.Binding="Click.[**NameOfViewModelMethod**]" >                                      </Button>  
查看完整描述

2 回答

?
一只斗牛犬

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊

你沒有顯示你所有的代碼和上下文,但它應(yīng)該像這樣工作我假設(shè)你在一個(gè)用戶控件中校準(zhǔn)父數(shù)據(jù)上下文......(以列表視圖為例):


<ListView   ItemsSource="{Binding listFromDataContext, IsAsync=True}" Margin="3,51,0,10"    >


<ListView.ItemTemplate >

<DataTemplate>

<grid>

 <Button   Command="{Binding DataContext.MyMethode, RelativeSource={RelativeSource AncestorType={x:Type controls:thisUserControl}}}" CommandParameter="{Binding}"   />

</grid>

</DataTemplate>

  </ListView.ItemTemplate >

</ListView>

然后在模型中


      private ICommand _MyMethode;

            public ICommand MyMethode

            {

                get

                {

                    return _MyMethode ?? (_MyMethode = new CommandHandler<MyModel.item>(x => showMessage(x), _canExecute));

                }

            }


public void showMessage(MyModel.item x)

{

MessageBox.Show(x.Info);

}


查看完整回答
反對(duì) 回復(fù) 2021-12-25
?
眼眸繁星

TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個(gè)贊

首先,如果您Button在 a 中Grid,DataContext則不需要設(shè)置Pathlike Path=ParentRow.DataContext

你的Command綁定應(yīng)該是這樣的:

<Button Command="{Binding YourVMICommand"} />

您必須public ICommand在 VM 中定義一個(gè),然后將其綁定到按鈕。


查看完整回答
反對(duì) 回復(fù) 2021-12-25
  • 2 回答
  • 0 關(guān)注
  • 179 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)