2

リソースを別のリソースから変更することは可能ですか? マウスが StartButtonMain の上にある場合、StartButtonRed の背景を変更するのが好きです。

<ImageBrush x:Key="RedBackgroundActive" ImageSource="/Images/start_red_active.png" Stretch="Fill"/>

<Style x:Key="StartButtonMain" TargetType="{x:Type local:SimpleButton}">
    <Style.Resources>
        <ImageBrush x:Key="MainBackground" ImageSource="/Images/start_main_normal.png" Stretch="Fill"/>
        <ImageBrush x:Key="MainBackgroundActive" ImageSource="/Images/start_main_active.png" Stretch="Fill"/>
    </Style.Resources>
    <Style.Setters>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
        <Setter Property="Background" Value="{StaticResource MainBackground}"/>
        <Setter Property="Visibility" Value="Visible"/>
    </Style.Setters>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="{StaticResource MainBackgroundActive}"/>
            // Change the background of StartButtonRed to RedBackgroundActive
        </Trigger>
    </Style.Triggers>
</Style>

<Style x:Key="StartButtonRed" TargetType="{x:Type local:SimpleButton}">
    <Style.Resources>
        <ImageBrush x:Key="RedBackground" ImageSource="/Images/start_red_normal.png" Stretch="Fill"/>
    </Style.Resources>
    <Style.Setters>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
        <Setter Property="Background" Value="{StaticResource RedBackground}"/>
        <Setter Property="Visibility" Value="Visible"/>
    </Style.Setters>
</Style>
4

1 に答える 1

0

これはできません。スタイルはリソースであり、トリガーは自身の Template 内から、または他の実際の FrameworkElement への Binding を使用して FrameworkElements をターゲットにすることしかできないため、別のリソースにバインドすることはできません。

これはUserControl Triggersで解決できます。

于 2012-07-03T11:02:04.173 に答える