1

WindowStateプロパティに基づいてLabelのコンテンツを更新しようとしています..私は次のものを持っています:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <Style x:Key="StyleMinMax" TargetType="{x:Type Label}">
            <Setter Property="TextElement.FontSize" Value="22" />
            <Setter Property="TextElement.FontWeight" Value="SemiBold" />
            <Setter Property="VerticalAlignment" Value="Stretch" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="Foreground" Value="LightSlateGray" />
            <Style.Triggers>
                <Trigger Property="Window.WindowState" Value="Normal">
                    <Setter Property="Content" Value="1-Normal" />
                </Trigger>
                <Trigger Property="Window.WindowState" Value="Maximized">
                    <Setter Property="Content" Value="2-Maximized" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <Grid>
        <Label Style="{StaticResource StyleMinMax}"></Label>
    </Grid>
</Window>

アプリケーションの起動時にラベルのコンテンツは 1-Normal になりますが、アプリケーションを最大化してもコンテンツは変化しません..何か考えはありますか?

前もって感謝します

4

1 に答える 1

6

トリガーを DataTriggers に更新する

     <DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Value="Normal">
             <Setter Property="Content" Value="1-Normal" />
      </DataTrigger>
     <DataTrigger Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"  Value="Maximized">
             <Setter Property="Content" Value="2-Maximized" />
      </DataTrigger>
于 2013-09-11T11:50:19.730 に答える