WPF Binding Programmatically

前端 未结 2 1762
遇见更好的自我
遇见更好的自我 2020-12-11 14:58

I am attempting to convert this xaml binding to it\'s C# counterpart for various reasons:



        
相关标签:
2条回答
  • 2020-12-11 15:33

    I believe that you need to make the ActualWidthProperty throw a NotifyPropertyChanged event. Otherwise, the binding will not know to update when the property changes. Whenever I've done bindings, I've always had to implement INotifyPropertyChanged.

    You might try extending the list view class and then implementing it on the width property. I gave a similar answer here: WPF Toolkit DataGrid column resize event

    0 讨论(0)
  • In the constructor of the PropertyPath the cell.Width gets the value, you either want EventCell.ActualWidthProperty to get the DP-field if it is a DP, or use the string, "ActualWidth".

    When translating XAML like this, just set the path in the Binding constructor which is the same constructor used in XAML (as the path is not qualified):

    Binding b = new Binding("ActualWidth");
    

    (If your binding were to be translated back to XAML it would be something like {Binding Path=123.4, ...}, note that the Path property is qualified as you did not use the constructor to set it)

    Edit: Also the binding needs to be set on the EventCell.WidthProperty of course, you cannot set the ActualWidth, it seems your logic was inverted...

    0 讨论(0)
提交回复
热议问题