0

現在、App.xml ファイルで Aero テーマを参照しています。main.xml ファイルでは、エキスパンダーを使用して、サイズ変更可能な幅のアプリにコンテンツを表示しています。(この例では、幅を 500 に制限しました)

通常、エキスパンダー ヘッダーの内容は短くなりますが、最大 500 文字まで可能です。ウィンドウのサイズ (デフォルトでは 600 ピクセル) によっては、コンテンツを折り返すことができます (これにより、エキスパンダー ヘッダーが下に引き伸ばされます)。これは問題ありませんが、トグル ボタン (円 /w 矢印) は、私が知る限り、VerticalAlignment=center に設定されています。

Expander の Aero テンプレートを再作成せずに、スタイルでその VerticalAlignment をオーバーライドする方法が必要です。円と矢印のオブジェクトを参照できないようです。トグルボタンもオーバーライドしようとしましたが、うまくいきませんでした。

以下に示すように、Aero Expander の一部の側面をオーバーライドできます。Toggle Button の Circle オブジェクトと Arrow オブジェクトを取得して VerticalAlignment を変更するには、ちょっとした調整が必要です。

ありがとう

コード例は次のとおりです。

<Window.Resources>
    <Style TargetType="{x:Type Expander}" BasedOn="{StaticResource {x:Type Expander}}">
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Background" Value="#464646" />
        <Setter Property="Width" Value="Auto" />
        <Setter Property="Margin" Value="1,0,1,0" />
        <Setter Property="IsExpanded" Value="False" />
    </Style>
</Window.Resources>

<Expander ContextMenu="{StaticResource cMnu}" Width="auto">
    <Expander.Header>
        <StackPanel Orientation="Horizontal" Width="auto" Margin="0">
            <TextBlock Width="65">Normal</TextBlock>
            <TextBlock Width="80">Open</TextBlock>
            <TextBlock Width="80">10/31/2009</TextBlock>
            <TextBlock TextWrapping="Wrap" Width="500">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
            Aliquam ultrices auctor magna, sit amet commodo ipsum accumsan eu. 
            Sed a mollis felis. Nam ullamcorper augue vel mauris consequat imperdiet. 
            Nunc in augue mauris. 
            Quisque metus tortor, porttitor nec auctor id, mollis nec ipsum. 
            Suspendisse eget ipsum vitae lectus fermentum porta. 
            Aliquam erat volutpat. 
            Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. 
            Phasellus congue dui ac arcu eleifend a amet.
            </TextBlock>
        </StackPanel>
    </Expander.Header>
</Expander>
4

1 に答える 1

1

のデフォルト テンプレートを見るとExpander、どのプロパティ セッターも機能していない理由がわかります。

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="20" />
    <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>
  <ToggleButton IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,
                RelativeSource={RelativeSource TemplatedParent}}"
                OverridesDefaultStyle="True" 
                Template="{StaticResource ExpanderToggleButton}" 
                Background="{StaticResource NormalBrush}" />
  <ContentPresenter Grid.Column="1"
                    Margin="4" 
                    ContentSource="Header" 
                    RecognizesAccessKey="True" />
</Grid>

はあなたが求めているものであり、そのためToggleButtonVerticalAlignmentセッターはありません。

を介してこの配置プロパティを変更する方法はないように思えStyleます。新しいテンプレートを提供する必要があります。

于 2009-08-25T22:25:46.657 に答える