質問

I have a ListView and binding ItemSource to a ICollectionView property, and binding selected item to a dp property.

 public static readonly DependencyProperty SelectedProperty =
      DependencyProperty.Register("Selected",
                                  typeof(Myclass),
                                  typeof(MyControl), new PropertyMetadata(SelectedContactChange));


    static void SelectedContactChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        MyControlcontrol = d as MyControl;
        control.MYView = CollectionViewSource.GetDefaultView(((Myclass)e.NewValue).Numbers);
    }

and i have another list view and binding itemsource to MYView propert.

 ICollectionView _myView;
    public ICollectionView MYView
    {
        get { return _myView; }
        set
        {
            _myView= value;
        }
    }

When change the SelectedProperty i set value for MYView, but don't show new value in listview that binding with MYView!!!

How to change MYView property when changed SelectedProperty ??

役に立ちましたか?

解決

Not 100% sure, but i guess that your ListView's ItemsSource is bound to the MYView property of your MyControl class, perhaps like this:

<MyControl x:Name="myControl" ... />
<ListView ItemsSource="{Binding MYView, ElementName=myControl}" />

When you now change the value of the MYView property, there is no mechanism that notifies the binding of the change. You should implement INotifyPropertyChanged and raise the PropertyChanged event when MYView changes:

public class MyControl : UserControl, INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public ICollectionView MYView
    {
        get { return _myView; }
        set
        {
            _myView = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("MYView"));
            }
        }
    }
}

Alternatively, you could define MYView as another dependency property.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top