2

私はちょっと奇妙な問題を抱えています。

これが状況です。私は を持っており、データをs に表示するようにListView定義されたカスタムがあり、その中に含まれるもの (1 つのトグル ボタン + 1 つのカスタム コントロールを含む)があります。ただし、 をチェックすると、カスタム コントロールが表示され、同じ行にある他のすべてのコントロールが垂直方向の中央に移動します。理想的には、これらのメンバーがトップに留まることを望んでいます。可能な限りどこでも設定しようとしましたが、とにかく変わりません。GroupStyleExpanderWrapPanelStackPanelsStackPanelToggleButtonToggleButtonVerticalAlignment="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 に設定するか、リストビューの 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 に答える