WrapPanel 中的 VerticalAlignment - 如何使其正常工作?
我遇到了一个有点奇怪的问题。
情况是这样的。我有一个 ListView
,带有自定义的 GroupStyle
以使数据出现在 Expander
中,其中有一个 WrapPanel
code> 包含 StackPanels
(其中包含一个 ToggleButton + 一个自定义控件) StackPanel
中的自定义控件默认不可见,但在选中 ToggleButton
时变为可见。 但是,当我检查 ToggleButton
时,会出现自定义控件,并且位于同一行的所有其他控件将移动到垂直中心。 理想情况下,我希望其他成员能够保持领先地位。我尝试在任何可以设置的地方设置 VerticalAlignment="Top"
,但无论如何它都不会改变。
成像问题:
扩展器的初始状态:
单击 ToggleButton
后,此处发生的情况是:
正如您所看到的,“测试分析”按钮已移至中心。我希望它保留在与原来相同的位置。
此外,我已在单独的 DataTemplate 对象中定义了所有这些样式。 这是一些简单的代码(我刚刚删除了对这里的问题无用的代码,不会让您阅读大量的 XAML 代码:)):
扩展器的内容属性:
<Expander.Content>
<WrapPanel Background="White" VerticalAlignment="Top">
<ItemsPresenter VerticalAlignment="Top"/>
</WrapPanel>
</Expander.Content>
列表的 ItemsPanel
:
<ItemsPanelTemplate >
<WrapPanel
Width="{Binding (FrameworkElement.ActualWidth),
RelativeSource={RelativeSource
AncestorType=Expander}}"
ItemWidth="{Binding (ListView.View).ItemWidth,
RelativeSource={RelativeSource AncestorType=ListView}}"
ItemHeight="{Binding (ListView.View).ItemHeight,
RelativeSource={RelativeSource AncestorType=ListView}}" />
</ItemsPanelTemplate>
列表的 项目模板
:
<StackPanel Orientation="Vertical" Height="Auto" Width="Auto" VerticalAlignment="Top" >
<ToggleButton BorderBrush="{x:Null}" Background="{x:Null}" IsChecked="{Binding Value.IsToLaunch, Mode=TwoWay}"
Command="{Binding DataContext.UpdateGroupCheckingsCommand,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UserControl}}}">
<Grid Background="Transparent">
<!-- Blah blah blah about the ToggleButton's content -->
</Grid>
</ToggleButton>
<my:UcReleaseChooser>
<!-- Blah blah blah about being visible if ToggleButton is Checked -->
</my:UcReleaseChooser>
</StackPanel>
I am having a kinda strange problem.
Here is the situation. I have a ListView
, with a custom defined GroupStyle
to make data appear in Expander
s, in which there is a WrapPanel
containing StackPanels
(which contain one ToggleButton + one custom control)
The custom control in the StackPanel
is not visible by default, and becomes visible when the ToggleButton
is checked.
However, when I check a ToggleButton
, the custom control appears, and all the other control situated on the same line will move to a vertical center.
Ideally, I'd like these other members to stay on top. I've tried to set VerticalAlignment="Top"
everywhere I could, it doesn't change anyway.
Imaged problem:
The initial state of an expander:
Once the ToggleButton
is clicked, here is what happens:
As you can see, the button "Test Analysis" is moved to stay at the center. I want it to stay in the same place than the original.
Moreover, I've defined all of these styles in separate DataTemplate
s objects.
Here is some light code (I just removed what's useless for the problem here, won't make you read tons of XAML code :) ):
The expander's content property:
<Expander.Content>
<WrapPanel Background="White" VerticalAlignment="Top">
<ItemsPresenter VerticalAlignment="Top"/>
</WrapPanel>
</Expander.Content>
The list's ItemsPanel
:
<ItemsPanelTemplate >
<WrapPanel
Width="{Binding (FrameworkElement.ActualWidth),
RelativeSource={RelativeSource
AncestorType=Expander}}"
ItemWidth="{Binding (ListView.View).ItemWidth,
RelativeSource={RelativeSource AncestorType=ListView}}"
ItemHeight="{Binding (ListView.View).ItemHeight,
RelativeSource={RelativeSource AncestorType=ListView}}" />
</ItemsPanelTemplate>
The list's ItemsTemplate
:
<StackPanel Orientation="Vertical" Height="Auto" Width="Auto" VerticalAlignment="Top" >
<ToggleButton BorderBrush="{x:Null}" Background="{x:Null}" IsChecked="{Binding Value.IsToLaunch, Mode=TwoWay}"
Command="{Binding DataContext.UpdateGroupCheckingsCommand,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UserControl}}}">
<Grid Background="Transparent">
<!-- Blah blah blah about the ToggleButton's content -->
</Grid>
</ToggleButton>
<my:UcReleaseChooser>
<!-- Blah blah blah about being visible if ToggleButton is Checked -->
</my:UcReleaseChooser>
</StackPanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将 VerticalAlignment 属性设置为 Top 或将列表视图的 VerticalContentAlignment 属性设置为 Stretch
或
Try setting the verticalalignment property to Top or the VerticalContentAlignment property of the listview to Stretch
or