ObservableCollection + CollectionChanged事件+ ResourceDictionnary [英] ObservableCollection + CollectionChanged event + ResourceDictionnary

查看:69
本文介绍了ObservableCollection + CollectionChanged事件+ ResourceDictionnary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我有一个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)
{
if (DayChanged == null
{
return ;
}

DayChanged( new DayChangedEventArgs(发件人< span class =code-keyword> as Day));
}





我在其他项目中使用我的Generic.xaml:



 <  扫描:日历    x:名称  = 日历    DayChanged   =   Calendar_DayChanged   保证金  =  0,82,0,0    Horizo​​ntalContentAlignment   = 中心 < span class =code-keyword> /  >  





当我第一次启动这个应用程序我收到已经在ListeTache中的每个项目的消息确定。



启动后,当我改变礼仪注释时,事件很火,没关系,但是当我在ListeTache中添加或删除元素时,我从未收到过任何事件。



我该怎么办?在此先感谢您的回复。

解决方案

Hello,

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.

解决方案

这篇关于ObservableCollection + CollectionChanged事件+ ResourceDictionnary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆