ColumnDefinition 在调整大小之前不会扩展
我有一个网格,其中一个列宽定义为 *
。 其他列定义为Auto
。 具有*
定义的列包含一个从Panel 派生的用户控件,该控件也实现了IScrollInfo
。 在此控件的 MeasureOverride
可见性设置为在另一列中的 RepeatButton
上可见(RepeatButton
的可见性否则设置为折叠)。
这不会导致列扩展。仅当我调整窗口大小时才会发生这种情况。 一个简化的示例:
<DockPanel LastChildFill="True">
<Grid DockPanel.Dock="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="TabItemColumn"/>
<ColumnDefinition x:Name="ScrollRightColumn" Width="Auto"/>
</Grid.ColumnDefinitions>
<ScrollViewer x:Name="PART_ScrollViewer"
Grid.Column="0"
Margin="-1,0,0,0"
Height="32"
CanContentScroll="True"
VerticalScrollBarVisibility="Hidden"
HorizontalScrollBarVisibility="Hidden"
HorizontalAlignment="Left">
<local:TabPanel
x:Name="tabPanel"
HorizontalAlignment="Left"
IsItemsHost="True" />
</ScrollViewer>
<RepeatButton Style="{StaticResource RepeatButtonScrollRight}"
Visibility="{Binding ElementName=tabPanel, Path=CanScrollRight, Converter={StaticResource _localBooleanConverter}}"
Grid.Column="1">
</RepeatButton>
RepeatButton
的可见性被正确触发,据我所知它实际上已渲染,但包含列的 ActualWidth
在调整大小之前为零。
有什么想法吗?
I have a grid where one columnwidth is defined as *
.
The other columns are defined as Auto
.
The column with the *
-definition contains a usercontrol derived from Panel that also implements IScrollInfo
.
During this control's MeasureOverride
visibility is set to visible on a RepeatButton
in another column (the RepeatButton
's visibility is otherwise set to collapsed).
This does not cause the column to expand. This will only occur when I resize my window.
A simplified example:
<DockPanel LastChildFill="True">
<Grid DockPanel.Dock="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="TabItemColumn"/>
<ColumnDefinition x:Name="ScrollRightColumn" Width="Auto"/>
</Grid.ColumnDefinitions>
<ScrollViewer x:Name="PART_ScrollViewer"
Grid.Column="0"
Margin="-1,0,0,0"
Height="32"
CanContentScroll="True"
VerticalScrollBarVisibility="Hidden"
HorizontalScrollBarVisibility="Hidden"
HorizontalAlignment="Left">
<local:TabPanel
x:Name="tabPanel"
HorizontalAlignment="Left"
IsItemsHost="True" />
</ScrollViewer>
<RepeatButton Style="{StaticResource RepeatButtonScrollRight}"
Visibility="{Binding ElementName=tabPanel, Path=CanScrollRight, Converter={StaticResource _localBooleanConverter}}"
Grid.Column="1">
</RepeatButton>
The visibility of the RepeatButton
is triggered correctly, and as far as I can tell it is actually rendered, but the ActualWidth
of the containing column is zero until resize.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改列宽后,您需要触发布局更改。在正确的父级上使用 InvalidateArrange()元素。注意避免无限循环。
You'll need to trigger a layout change after changing the column width. Use InvalidateArrange() on the proper parent element. Take care to avoid infinite cycles.
InvalidateArrange
是一个很好的答案,但不幸的是,在实际安排控件时,它被默默地忽略了。所以诀窍是在排列完成后调用它。这可能有效(我没有尝试过):
如果这不起作用,您可以尝试在 RepeatButton 上调用 InvalidateArrange 和/或 InvalidateMeasure,也在 Dispatcher.BeginInvoke 回调中调用。
InvalidateArrange
is a good answer, but unfortunately it is silently ignored during the time a control is actually being arranged. So the trick is to call it after the arrange is complete.This may work (I haven't tried it):
If this doesn't work, you might try calling InvalidateArrange and/or InvalidateMeasure on the RepeatButton, also within a Dispatcher.BeginInvoke callback.