我正在尝试将DataGrid中列的宽度绑定到应用程序设置属性。当绑定模式设置为单向模式时,我已经成功实现了这一点,但是,当应用程序关闭时,需要根据列的宽度更新该设置。当我将绑定模式更改为双向时,绑定完全中断。我的代码如下,如何实现这一点?
扩展类
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
xaml
xmlns:w="clr-namespace:Stack"
<DataGrid>
...
<DataGridTextColumn Header="STACK"
Width="{w:SettingBinding StackColumnWidth}"/>
...
</DataGrid>