WrapPanel中的VerticalAlignment - 如何使其正常工作?

Dam*_*cus 2 wpf wrappanel datatemplate wpf-controls vertical-alignment

我有一个奇怪的问题.

情况就是这样.我有一个ListView定制的自定义GroupStyle,使数据显示在Expanders中,其中有一个WrapPanel包含StackPanels(包含一个ToggleButton +一个自定义控件)StackPanel默认情况下,自定义控件不可见,并在ToggleButton选中时显示.但是,当我检查a时ToggleButton,会出现自定义控件,位于同一行的所有其他控件将移动到垂直中心.理想情况下,我希望其他成员能够保持领先地位.我试着尽VerticalAlignment="Top"我所能,不管怎样都不会改变.

成像问题:

扩展器的初始状态:

之前扩张

一旦ToggleButton被点击时,会出现以下情况:

扩张后

如您所见,"测试分析​​"按钮移动到中心位置.我希望它与原版保持在同一个地方.

而且,我已经在单独的DataTemplates对象中定义了所有这些样式.这里有一些轻量代码(我刚刚删除了这里的问题无用,不会让你阅读大量的XAML代码:)):

扩展器的内容属性:

<Expander.Content>
    <WrapPanel Background="White" VerticalAlignment="Top">
        <ItemsPresenter VerticalAlignment="Top"/>
    </WrapPanel>
</Expander.Content>
Run Code Online (Sandbox Code Playgroud)

清单的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>
Run Code Online (Sandbox Code Playgroud)

清单的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>
Run Code Online (Sandbox Code Playgroud)

bij*_*iju 5

尝试将verticalalignment属性设置为Top,或将listview的VerticalContentAlignment属性设置为Stretch

   <Style TargetType="ListView">
        <Setter Property="VerticalContentAlignment" Value="Top"/>
    </Style>
Run Code Online (Sandbox Code Playgroud)

要么

    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="VerticalContentAlignment" Value="Stretch" />
        </Style>
    </ListView.ItemContainerStyle>
Run Code Online (Sandbox Code Playgroud)