C# 启用基于父命令的WPF样式化子控件

C# 启用基于父命令的WPF样式化子控件,c#,wpf,button,styles,label,C#,Wpf,Button,Styles,Label,我只想使我的按钮内的标签看起来被禁用。搜索互联网,这似乎是一个简单的任务,我做错了什么 <Button Command="{Binding CommandProcess}"> <StackPanel Orientation="Horizontal"> <Image Source="Images\Cloud-Upload.png"/> <Label Content="Upload and Process" Fore

我只想使我的
按钮内的
标签
看起来被禁用。搜索互联网,这似乎是一个简单的任务,我做错了什么

<Button Command="{Binding CommandProcess}">
    <StackPanel Orientation="Horizontal">
        <Image Source="Images\Cloud-Upload.png"/>

        <Label Content="Upload and Process" Foreground="White" VerticalAlignment="Center" FontWeight="Bold" FontSize="18.667" Margin="5,0,0,0">
            <Label.Style>
                <Style TargetType="Label">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=IsEnabled, RelativeSource={RelativeSource AncestorType={x:Type Button}}}" Value="False">
                            <Setter Property="Foreground" Value="Gray"></Setter>
                            <Setter Property="ToolTip" Value="Please select a record type for each file selected for processing"></Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Label.Style>
        </Label>
    </StackPanel>
</Button>

改用
ElementName
RelativeSource=FindAncestor
在这里不起作用,因为按钮不在可视树中,而是StackPanel的同级。为按钮指定
名称
,并使用
ElementName
-

<Button Command="{Binding CommandProcess}" x:Name="MyButton">
可以看出,Button是StackPanel的兄弟,它现在位于标签的可视树中,这就是为什么
FindAncestor
无法让您访问
Button

非常感谢,必须添加一个“白色”setter,但效果很好,再次感谢
<Button Command="{Binding CommandProcess}" x:Name="MyButton">
<DataTrigger Binding="{Binding Path=IsEnabled, ElementName=MyButton}"
             Value="False">
   .....
</DataTrigger>
Label <--- StackPanel <--- StackPanel's Parent
Button <--- StackPanel's Parent