ObservableCollection + CollectionChanged事件+ ResourceDictionnary [英] ObservableCollection + CollectionChanged event + ResourceDictionnary
问题描述
你好, Hello, 这篇关于ObservableCollection + CollectionChanged事件+ ResourceDictionnary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
我有一个Day.cs课程有这个优点:
< pre lang =c#> public ObservableCollection ListeTache
{
get {< span class =code-keyword> return this ._ listeTache; }
set
{
_listeTache = value ;
if (PropertyChanged!= null )
{
PropertyChanged( 此, new PropertyChangedEventArgs( ListeTache跨度>));
}
}
}
public string Notes
{
get { return 此跨度> ._笔记; }
set
{
_notes = value ;
if (PropertyChanged!= null )
{
PropertyChanged( 此, new PropertyChangedEventArgs( 注释跨度>));
}
}
}
public bool 已启用
{
获取 {返回 _enabled; }
set
{
_enabled = value ;
if (PropertyChanged!= null )
{
PropertyChanged( 此, new PropertyChangedEventArgs( 启用跨度>));
}
}}
我的Day.cs课程有:
public Day(){
_listeTache = new ObservableCollection();
_listeTache.CollectionChanged + = ListeTache_Changed;
}
private void ListeTache_Changed( object sender,NotifyCollectionChangedEventArgs e)
{
MessageBox.Show( OK跨度>);
}
我绑这样的笔记:
< TextBox IsEnabled = {Binding IsEnabled} 文字 = {Binding Notes,Mode = TwoWay,UpdateSourceTrigger = PropertyChanged} AcceptsReturn = True TextWrapping = Wrap BorderThickness = 0 ScrollViewer .VerticalScrollBarVisibility = 自动 已删除 = {x:Null} 前景 = 白色 / >
我像这样绑定ListeTache:
< ListBox x:名称 = 清单当然Taches IsEnabled = {Binding IsEnabled} ItemsSource < span class =code-keyword> =
{Binding ListeTache} IsSynchronizedWithCurrentItem = True FontSize = 10 PreviewMouseDown = PreviewMouseDownClick_clear MouseDoubleClick = doubleClic >
< Style.Triggers >
在我的班级Calendar.cs中我有这个活动:
private void Day_Changed( object sender,PropertyChangedEventArgs e)
Day));
{
if (DayChanged == null )
{
return ;
}
DayChanged(此, new DayChangedEventArgs(发件人< span class =code-keyword> as
}
我在其他项目中使用我的Generic.xaml:
< 扫描:日历 x:名称 = 日历 DayChanged = Calendar_DayChanged 保证金 = 0,82,0,0 HorizontalContentAlignment = 中心 < span class =code-keyword> /
>
当我第一次启动这个应用程序我收到已经在ListeTache中的每个项目的消息确定。
启动后,当我改变礼仪注释时,事件很火,没关系,但是当我在ListeTache中添加或删除元素时,我从未收到过任何事件。
我该怎么办?在此先感谢您的回复。
I have a Day.cs class who have this propriety :
public ObservableCollection ListeTache
{
get { return this._listeTache; }
set
{
_listeTache = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("ListeTache"));
}
}
}
public string Notes
{
get { return this._notes; }
set
{
_notes = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Notes"));
}
}
}
public bool Enabled
{
get { return _enabled; }
set
{
_enabled = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Enabled"));
}
} }
My Day.cs class have :
public Day(){
_listeTache = new ObservableCollection();
_listeTache.CollectionChanged += ListeTache_Changed;
}
private void ListeTache_Changed(object sender, NotifyCollectionChangedEventArgs e)
{
MessageBox.Show("ok");
}
I bind Notes like that :
<TextBox IsEnabled="{Binding IsEnabled}" Text="{Binding Notes, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="True" TextWrapping="Wrap" BorderThickness="0" ScrollViewer.VerticalScrollBarVisibility="Auto" removed="{x:Null}" Foreground="White" />
I bind ListeTache like that :
<ListBox x:Name="ListeTaches" IsEnabled="{Binding IsEnabled}" ItemsSource="{Binding ListeTache}" IsSynchronizedWithCurrentItem="True" FontSize="10" PreviewMouseDown="PreviewMouseDownClick_clear" MouseDoubleClick="doubleClic">
<Style.Triggers>
In my class Calendar.cs I have this event :
private void Day_Changed(object sender, PropertyChangedEventArgs e)
{
if (DayChanged == null)
{
return;
}
DayChanged(this, new DayChangedEventArgs(sender as Day));
}
I use my Generic.xaml in other projet like that :
<Scan:Calendar x:Name="Calendar" DayChanged="Calendar_DayChanged" Margin="0,82,0,0" HorizontalContentAlignment="Center"/>
When I start this app for the first time I receive my message "ok" for each items already in ListeTache.
After starting, When I change the propriety "Notes", the event is fire and it's okay but when I add or Remove an element in my ListeTache I never get an event.
How can I do ? Thanks in advance for your reply guys.