问题描述
所以我有一个带有一列定义的网格.初始列宽属性是从应用程序的设置初始化的,该属性可以正常运行,然后我尝试为列设置最大大小,以使用户无法调整屏幕大小,从而无法正确显示内容.
So I have this grid with a bunch of column definitions. The initial column width property is initialized from the settings of the app, which works correctly, then I try to make a max size for the columns so that the user cannot resize the screen so that things don't appear correctly.
用于计算最大宽度的多重绑定似乎正常工作.但是,我遇到的问题是,当网格拆分器更改实际宽度的值时,多重绑定不会重新计算MaxWidth的值.我在转换器内部设置了一个断点,但是没有命中.
The multibinding that is used to calculate the max width seems to be working properly. However, the issue I have is that the multibinding does not Recalculate the value of MaxWidth when a gridsplitter changes the values of the actual width. I have a breakpoint set inside the converter but it is not hit.
但是,我不知道怎么回事,因为根据GridSplitter的文档:
However, I don't see how that can be, because according to GridSplitter's documentation:
http://msdn.microsoft.com/zh-CN/library/system.windows.controls.gridsplitter%28v=vs.110%29.aspx
使用网格拆分器调整大小应更改列定义的实际宽度.
Resizing with a gridsplitter should change the actualwidth of a columndefinition.
如果是这种情况,那么我希望多重绑定能够更新.但是,我没有看到这个.
If that is the case, then I would expect the multibinding to update. However, I'm not seeing this.
<Grid.ColumnDefinitions>
<ColumnDefinition
x:Name="NameListViewColumn"
MinWidth="100"
Width="{Binding NameListViewWidth, Source={x:Static DaedalusGraphViewer:SettingsManager.AppSettings}, Mode=OneTime,
Converter={StaticResource GridLengthConverter}}"
>
<ColumnDefinition.MaxWidth>
<MultiBinding Converter="{StaticResource SignalNameColumnMaxSizeConverter}">
<Binding Path="ActualWidth"
ElementName="NameListViewColumn"
/>
<Binding Path="ActualWidth"
ElementName="SignalValuesListViewColumn"
/>
<Binding Path="ActualWidth"
ElementName="SignalTreeViewColumn"
/>
<Binding ElementName="SignalValuesListViewColumn" Path="MinWidth" />
<Binding ElementName="SignalTreeViewColumn" Path="MinWidth" />
</MultiBinding>
</ColumnDefinition.MaxWidth>
</ColumnDefinition>
<ColumnDefinition Width="Auto" x:Name="SignalNamesGridSpitter"/>
<ColumnDefinition
MinWidth="100"
x:Name="SignalValuesListViewColumn"
Width="{Binding SignalValuesListViewWidth, Source={x:Static DaedalusGraphViewer:SettingsManager.AppSettings},
Mode=OneTime, Converter={StaticResource GridLengthConverter}}"
>
<ColumnDefinition.MaxWidth>
<MultiBinding Converter="{StaticResource SignalValuesMaxSizeConverter}">
<Binding Path="ActualWidth"
ElementName="SignalValuesListViewColumn"
/>
<Binding Path="ActualWidth"
ElementName="SignalTreeViewColumn"
/>
<Binding ElementName="SignalTreeViewColumn" Path="MinWidth" />
</MultiBinding>
</ColumnDefinition.MaxWidth>
</ColumnDefinition>
<ColumnDefinition x:Name="SignalValuesGridSplitter" Width="Auto"/>
<ColumnDefinition
x:Name="SignalTreeViewColumn"
MinWidth="100"
Width="*"
/>
<ColumnDefinition Width="18" MinWidth="18" x:Name="VerticalScrollBarColumn"/>
</Grid.ColumnDefinitions>
推荐答案
在这里找到了答案:基本上,实际的width属性没有实现INotifyPropertyChanged.
Found the answer here: basically the actual width property doesn't implement INotifyPropertyChanged.
绑定到ColumnDefinition.ActualWidth返回0
这篇关于WPF如何在GridSplitter列调整大小时使Grid重新评估最大宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!