我正在尝试将 DataGrid 中列的宽度绑定到应用程序设置属性。当绑定设置为 OneWay 模式时,我可以正常工作,但是,我需要在应用程序关闭时根据列的宽度更新设置。当我将绑定模式更改为 TwoWay 时,绑定会一起中断。我的代码如下,我该如何实现呢?
扩展类
Public Class SettingBindingExtension
Inherits Binding
Public Sub New()
Initialize()
End Sub
Public Sub New(ByVal path As String)
MyBase.New(path)
Initialize()
End Sub
Private Sub Initialize()
Me.Source = MySettings.[Default]
'OneWay mode works for the initial grid load but any resizes are unsaved.
Me.Mode = BindingMode.OneWay
'using TwoWay mode below breaks the binding...
'Me.Mode = BindingMode.TwoWay
End Sub
End Class
xml
xmlns:w="clr-namespace:Stack"
<DataGrid>
...
<DataGridTextColumn Header="STACK"
Width="{w:SettingBinding StackColumnWidth}"/>
...
</DataGrid>