2

我有一个奇怪的问题。

这是情况。我有一个ListView, 定义了一个自定义GroupStyle来使数据出现在Expanders 中,其中有一个WrapPanel包含StackPanels(其中包含一个 ToggleButton + 一个自定义控件) 中的自定义控件StackPanel默认情况下是不可见的,并且在ToggleButton选中时变为可见。但是,当我检查 a 时ToggleButton,会出现自定义控件,并且位于同一行的所有其他控件将移动到垂直中心。理想情况下,我希望这些其他成员保持领先。我试图设置VerticalAlignment="Top"任何我可以设置的地方,它无论如何都不会改变。

图像问题:

扩展器的初始状态:

之前的扩展器

ToggleButton单击 后,会发生以下情况:

后扩展器

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

此外,我已经在单独DataTemplate的 s 对象中定义了所有这些样式。这是一些简单的代码(我只是在这里删除了对问题无用的内容,不会让您阅读大量 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>

名单的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>
4

1 回答 1

5

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

   <Style TargetType="ListView">
        <Setter Property="VerticalContentAlignment" Value="Top"/>
    </Style>

或者

    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="VerticalContentAlignment" Value="Stretch" />
        </Style>
    </ListView.ItemContainerStyle>
于 2011-04-27T12:45:56.850 回答