A DataTrigger is a type of trigger in WPF (Windows Presentation Foundation) that sets property values or applies styles based on the value of a data-bound property. This means that when a specific property of a data object changes, a DataTrigger can be used to dynamically modify the appearance or behavior of a UI element.

For example, you could use a DataTrigger to change the background color of a button based on a condition in the data. If the data property "IsEnabled" is set to false, the button's background could be set to gray.

Here's an example of a DataTrigger that sets the background color of a button based on the value of a data-bound property:

<Button Content="Click me">
    <Button.Style>
        <Style TargetType="Button">
            <Setter Property="Background" Value="Green" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsEnabled}" Value="False">
                    <Setter Property="Background" Value="Gray" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>

In this example, the button's background is initially set to green. However, if the "IsEnabled" property of the data object bound to the button is set to false, the DataTrigger sets the background to gray.

DataTrigger

原文地址: https://www.cveoy.top/t/topic/LVt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录