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

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

將 ObservableCollection 綁定到 ListBox ItemsSource

將 ObservableCollection 綁定到 ListBox ItemsSource

C#
縹緲止盈 2021-07-20 21:12:09
我在讓我的 ListBox 從 ObservableCollection 的更改中更新時(shí)遇到了一些麻煩。我將 ListBox 的 ItemsSource 綁定到 ObservableCollection,但 ListBox 仍然拒絕顯示任何內(nèi)容。如果我實(shí)現(xiàn) INotifyPropertyChanged,并在每次更改集合時(shí)引發(fā)屬性更改事件,則它可以工作。但是我認(rèn)為如果我使用 ObservableCollection 就不必這樣做了。我應(yīng)該怎么做才能使 ListBox 更新并適當(dāng)?shù)仫@示 ObservableCollection?Xml:<Window x:Name="window" x:Class="testApp.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"        xmlns:local="clr-namespace:testApp"        mc:Ignorable="d"        Title="MainWindow" Height="350" Width="525" DataContext="{Binding Mode=OneWay, RelativeSource={RelativeSource Self}}">    <StackPanel Margin="0">        <Button Content="Add" HorizontalAlignment="Left" Height="24" Margin="5,5,0,0" Width="100" Click="Button_Click"/>        <ListBox Height="140" Margin="5,5,5,0" VerticalAlignment="Top" ItemsSource="{Binding MyStrings, ElementName=window}"/>    </StackPanel></Window>代碼隱藏:namespace testApp{    /// <summary>    /// Interaction logic for MainWindow.xaml    /// </summary>    public partial class MainWindow : Window    {        public MainWindow()        {            InitializeComponent();            MyStrings = new ObservableCollection<string> { "Boop" };        }        public ObservableCollection<string> MyStrings { get; private set; }        private void Button_Click(object sender, RoutedEventArgs e)        {            MyStrings.Add("New String");        }    }}
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 259 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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