WPF how to make Grid Reevaluate Max Widths on GridSplitter Column Resize?

[亡魂溺海] 提交于 2020-01-15 15:10:58

问题


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.

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.

However, I don't see how that can be, because according to GridSplitter's documentation:

http://msdn.microsoft.com/en-us/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>

回答1:


Found the answer here: basically the actual width property doesn't implement INotifyPropertyChanged.

Binding to ColumnDefinition.ActualWidth returns 0




回答2:


MaxWidth="{Binding ElementName=SignalValuesGridSplitter,Path=ActualWidth}" TextWrapping="Wrap"/>

hope it helps



来源:https://stackoverflow.com/questions/22416949/wpf-how-to-make-grid-reevaluate-max-widths-on-gridsplitter-column-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!