WPF MultiBinding in Convertor fails ==> DependencyProperty.UnsetValue

前端 未结 5 996
故里飘歌
故里飘歌 2020-12-31 10:23

My code fails at at startup because the values array in the Converter that is called by the Multibinding is not filled with proper value bu

5条回答
  •  Happy的楠姐
    2020-12-31 10:59

    When you set a list in any ItemsSource, the DataTemplate's DataContext for the individual items will each item of the list.

    True that your TextBlock binding is working correctly, because the DataContext is set to your main object: PageViewModel

    But in your DataTemplate the DataContext will be set to PageNumberViewModel, since these are the items in your collection.

    Therefor, the binding to Path=CurrentPage.Page_Number will result to UnsetValue, because CurrentPage is not a property of PageNumberViewModel

    Hope this clarifies things!

    If you truly wish to bind to the CurrentPage property of your Window's DataContext, consider using an ElementName binding:

    Give window a name, bind to

    
    

    or use a RelativeSource binding:

    
    

提交回复
热议问题