I created a custom UserControl. It has a custom Dependency Property. A style has a Data Trigger using that property. When the form loads ExpectsFunction.get() is called twice. Then I externally set ExpectsFunction to true. If I put a breakpoint in the setter, I see that SetValue is called properly, and the property ExpectsFunction becomes 'true'. However, the DataTrigger doesn't seem to react to the change. Do I need to implement some additional event, or implement INotifyPropertyChanged and manually trigger PropertyChanged from the callback of the DependencyProperty? I thought the DataTrigger would subscribe to the DependencyProperty, but it doesn't seem to be the case :/
public partial class MatlabScriptSettings : UserControl
{
public static readonly DependencyProperty ExpectsFunctionProperty =
DependencyProperty.Register("ExpectsFunctionProperty", typeof(bool), typeof(MatlabScriptSettings), new PropertyMetadata(false));
public bool ExpectsFunction
{
get
{
return (bool)GetValue(ExpectsFunctionProperty);
}
set
{
SetValue(ExpectsFunctionProperty, value);
}
}
}
<UserControl x:Class="PlatformManager.UI.Configuration.MatlabScriptSettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="350"
x:Name="_this">
<UserControl.Resources>
<Style x:Key="ArgumentsStyle" TargetType="{x:Type TextBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=_this, Path=ExpectsFunction}" Value="True">
<Setter Property="IsReadOnly" Value="False" />
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=_this, Path=ExpectsFunction}" Value="False">
<Setter Property="IsReadOnly" Value="True" />
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" />
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
...
<TextBox Name="ScriptArguments" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Margin="5,5,0,0" Text="{Binding Path=ScriptArguments}" Style="{StaticResource ResourceKey=ArgumentsStyle}" />
...
Thanks!
Easy (after wasting 4 hours :/)... the string of the property name must not contain Property .
public static readonly DependencyProperty ExpectsFunctionProperty =
DependencyProperty.Register("ExpectsFunction", typeof(bool), typeof(MatlabScriptSettings), new PropertyMetadata(false));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.