Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 按钮样式取决于Window.IsActive_Wpf_Xaml_.net 3.5 - Fatal编程技术网

Wpf 按钮样式取决于Window.IsActive

Wpf 按钮样式取决于Window.IsActive,wpf,xaml,.net-3.5,Wpf,Xaml,.net 3.5,我需要让一个按钮根据窗口改变其样式。IsActive属性-当窗口失去焦点时,前景色应该改变 以下代码不会导致任何更改: <Style TargetType="Button" x:Key="SYS_Window_Button"> <Setter Property="Foreground" Value="{StaticResource SYS_Window_Button_Text}" /> <Setter Prop

我需要让一个按钮根据
窗口改变其样式。IsActive
属性-当窗口失去焦点时,前景色应该改变

以下代码不会导致任何更改:

<Style TargetType="Button"
       x:Key="SYS_Window_Button">
    <Setter Property="Foreground"
            Value="{StaticResource SYS_Window_Button_Text}" />

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border Background="{TemplateBinding Background}">
                    <ContentPresenter x:Name="MyContentPresenter"
                                      Content="{TemplateBinding Content}"
                                      HorizontalAlignment="Center"
                                      VerticalAlignment="Center"
                                      Margin="0" />
                </Border>

                <ControlTemplate.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=IsActive}"
                                 Value="False">
                        <Setter Property="Foreground"
                                Value="Red" />
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


有什么想法吗?

我试过了,效果很好。你是如何将这种风格应用到你的按钮上的?。我尝试使用静态值而不是前台资源。。。你能试着把静态颜色值而不是StaticResource…放进去吗?当窗口失去焦点时前景会改变吗?我无法让它工作,即使使用静态颜色值而不是资源。是的。。它正在改变。。当我的窗口不是activeHum时-应该早点检查这个。。。如果按钮有文本内容,那么代码就可以正常工作。该按钮仅包含路径/几何图形。谢谢你,尼特。。。