I have a user control and in it I have several textbox / calendar / ... controls that should all be enabled or disabled based on the properties in my user control (IsEditing)
I created the IsEditing dependency property in my user control, and now I want to define the style that all controls use to enable or disable it.
I am trying to do something like this:
<ad:DocumentContent.Resources> <Style x:Key="ReadOnlyMode"> <Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="VerticalAlignment" Value="Stretch"/> <Setter Property="Visibility" Value="Visible"/> <Setter Property="IsEnabled" Value="False" /> <Style.Triggers> <Trigger Property="IsEditing" Value="True"> <Setter Property="Background" Value="Green"/> </Trigger> </Style.Triggers> </Style> </ad:DocumentContent.Resources>
But I get this error: the IsEditing property was not found in the type "FrameworkElement".
How can I access the correct property for triggers?
Update 1:
I defined IsEditing as follows:
public static readonly DependencyProperty IsEditingProperty = DependencyProperty.Register( "IsEditing", typeof(Boolean), typeof(MyDetailDataControl), new PropertyMetadata(false));
And the following styles are defined:
<ad:DocumentContent.Resources> <Style x:Key="ReadOnlyMode" xmlns:u="clr-namespace:MyProject.Controls" TargetType="{x:Type u:MyDetailDataControl}"> <Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="VerticalAlignment" Value="Stretch"/> <Setter Property="Visibility" Value="Visible"/> <Setter Property="IsEnabled" Value="False" /> <Style.Triggers> <Trigger Property="IsEditing" Value="True"> <Setter Property="Background" Value="Green"/> </Trigger> </Style.Triggers> </Style> </ad:DocumentContent.Resources>
But now I get the following error: The property "IsEditing" was not found in the type "MyDetailDataControl".
I think there is a problem with defining a dependency property.
Update 2:
I changed xaml as follows (add xmlns: l = "clr-namespace: MyProject.Controls" in the user control section to make the namespace accessible everywhere), and also used the method defined here http://www.wpfmentor.com /2009/01/how-to-debug-triggers-using-trigger.html for debugging the launch)
<ad:DocumentContent.Resources> <Style x:Key="ReadOnlyMode" TargetType="TextBox"> <Style.Triggers> <Trigger my:TriggerTracing.TriggerName="BoldWhenMouseIsOver" my:TriggerTracing.TraceEnabled="True" Property="l:MyDetailDataControl.IsEditing" Value="True"> <Setter Property="TextBox.Background" Value="Green"/> </Trigger> </Style.Triggers> </Style> </ad:DocumentContent.Resources>
But does the trigger fail? Need to implement attribute notification mechanism? if so, how can i do this? Is there any special way to notify me when a property changes when the property is an attached property?
Update 3: Changed this version, which is not related to my own IsEditing property. But still does not work.
<ad:DocumentContent.Resources> <Style x:Key="MyStyle" TargetType="{x:Type l:MyDetailDataControl}" > <Style.Triggers> <Trigger my:TriggerTracing.TriggerName="BoldWhenMouseIsOver" my:TriggerTracing.TraceEnabled="True" Property="IsMouseOver" Value="True"> <Setter Property="FontWeight" Value="Bold"/> </Trigger> </Style.Triggers> </Style> </ad:DocumentContent.Resources>