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

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

如何更新 xaml 中沒有綁定控件的集合項(xiàng)屬性?

如何更新 xaml 中沒有綁定控件的集合項(xiàng)屬性?

C#
函數(shù)式編程 2023-12-17 16:48:52
我有一系列物品,例如: class Myclass : INotifyPropertyChanged {     public bool Selected { get; set; }     public string ChosenValue { get; set; } }然后我就有了這個(gè)類的可觀察集合: public ObservableCollection<Myclass> _myObColl最后,我有一個(gè)綁定到 _myObColl 的列表框和一個(gè)綁定到另一個(gè)集合的單獨(dú)組合框。我想要更新組合框以更新 _myObColl 列表中所有項(xiàng)目的 ChosenValue 屬性。但我不知道怎么做。組合框選定的項(xiàng)目綁定到視圖模型中名為 currselection 的屬性。我想要做的是將 Myclass 的 ChosenValue 屬性綁定到 currselection 值。但我該怎么做呢?也許我不應(yīng)該考慮綁定,但我想不出另一種方法來更新項(xiàng)目的 ChosenValue 屬性。我嘗試了組合的 SelectionChanged 事件來循環(huán)_myObColl。除非在更改組合框后將某個(gè)項(xiàng)目標(biāo)記為選中,否則此方法有效。<ComboBox ItemsSource="{Binding Path=DataContext.lstComboList , ElementName=PS4}" SelectedItem="{Binding Path=currselection, Mode=TwoWay}" Margin="10,10,10,10" Width="100"/>     <ListBox ItemsSource="{Binding _myObColl}" Margin="10,10,0,0" >            <ListBox.ItemTemplate x:Uid="asdasd"  >                <DataTemplate>                     <Grid>                        <Grid.RowDefinitions>                                <RowDefinition Height="Auto"/>                        </Grid.RowDefinitions>                        <Grid.ColumnDefinitions>                            <ColumnDefinition Width="Auto" />                        </Grid.ColumnDefinitions>                                 <CheckBox Grid.Column ="3" Width="50" VerticalAlignment="Center" Margin="10"  IsChecked="{Binding Path=PropA, Mode=TwoWay}"/>                    </Grid>                 </DataTemplate>             </ListBox.ItemTemplate>    </ListBox>
查看完整描述

1 回答

?
瀟湘沐

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

如果您希望組合框更改列表框中所選項(xiàng)目的值,您可以像這樣綁定 SelectedItem。


<ComboBox ItemsSource="{Binding ComboList}" SelectedItem="{Binding ElementName=listBox, Path=SelectedItem.ChosenValue}" />

否則,如果您確實(shí)想在組合框更改時(shí)更改列表中所有項(xiàng)目的屬性,則需要在屬性設(shè)置器中的代碼后面執(zhí)行此操作。


<ComboBox ItemsSource="{Binding ComboList}" SelectedItem="{Binding SelectedValue}"/>

在視圖模型中


private string _SelectedValue;

public string SelectedValue

{

    get => _SelectedValue;

    set

    {

        _SelectedValue = value;

        foreach (var item in MyObColl.ToList()) item.ChosenValue = _SelectedValue;

    }

}


查看完整回答
反對 回復(fù) 2023-12-17
  • 1 回答
  • 0 關(guān)注
  • 163 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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