Answered by:
Trigger condition throws as Exception "Must have non-null value for 'Property'."

Question
-
In my custom control, inherited from Window, I need a property IsMouseLeftDown, so I created a DependencyProperty.
public class MyWindow : Window { #region Properties public static readonly DependencyProperty IsLeftMouseDownProperty = DependencyProperty.Register( "IsLeftMouseDownProperty", typeof(bool), typeof(MyWindow), new UIPropertyMetadata(null) ); public bool IsLeftMouseDown { get { return (bool)GetValue(IsLeftMouseDownProperty); } set { SetValue(IsLeftMouseDownProperty, value); ; } } #endregion static MyWindow() { DefaultStyleKeyProperty.OverrideMetadata(typeof(MyWindow), new FrameworkPropertyMetadata(typeof(MyWindow))); } public MyWindow() { IsLeftMouseDown = false; } }
The problem is that the condition IsLeftMouseDown == true throws an exception "Must have non-null value for 'Property'." Why this is happening?
<Style TargetType="{x:Type local:MyWindow}"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:MyWindow}"> <Grid Background="{TemplateBinding Background}"> <ContentPresenter></ContentPresenter> </Grid> <ControlTemplate.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True"/> <Condition Property="IsLeftMouseDown" Value="True"/> </MultiTrigger.Conditions> <Setter Property="Background" Value="Green"/> </MultiTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
- Edited by Djura Tuesday, January 4, 2011 4:33 PM bad formationg
Tuesday, January 4, 2011 4:30 PM
Answers
-
Change new UIPropertyMetadata(null) to new UIPropertyMetadata(false)
- Proposed as answer by noorbakhsh Tuesday, January 4, 2011 5:59 PM
- Marked as answer by Djura Tuesday, January 4, 2011 8:55 PM
Tuesday, January 4, 2011 5:57 PM
All replies
-
Change new UIPropertyMetadata(null) to new UIPropertyMetadata(false)
- Proposed as answer by noorbakhsh Tuesday, January 4, 2011 5:59 PM
- Marked as answer by Djura Tuesday, January 4, 2011 8:55 PM
Tuesday, January 4, 2011 5:57 PM -
As Brian has mentioned changing the default value to false should fix this. It also makes sense since the value for IsLeftMouseDownProperty should be false by default. It is either true or false with null being meaningless.
noorbakhsh حميد نوربخشTuesday, January 4, 2011 6:11 PM -
Change new UIPropertyMetadata(null) to new UIPropertyMetadata(false)
The change did not solve problem.
Tuesday, January 4, 2011 8:10 PM -
Your other problem is your copying and pasting. Change DependencyProperty.Register("IsLeftMouseDownProperty", ...) to DependencyProperty.Register("IsLeftMouseDown", ...)
Your property name and registration don't match.
Tuesday, January 4, 2011 8:34 PM