What I have is a custom window. Added a bool dependencyproperty. I want to use this dependency property as a condition for my triggers. A way to get around my triggers so to speak. Unfortunately I have propery non-null value exception being thrown. Banging my head with this one. I also tested the dependency property before the binding on the triggers. It never hits the dependency property wrapper. No errors thrown/shown when I do that.
DependencyProperty setup:
/// <summary>
/// The override visibility property
/// </summary>
public static readonly DependencyProperty OverrideVisibilityProperty = DependencyProperty.Register(
"OverrideVisibility", typeof(bool), typeof(MyWindow), new PropertyMetadata(false));
/// <summary>
/// Gets or sets the override visibility.
/// </summary>
/// <value>The override visibility.</value>
public bool OverrideVisibility
{
get
{
return (bool)this.GetValue(OverrideVisibilityProperty);
}
set
{
this.SetValue(OverrideVisibilityProperty, value);
}
}
Trigger setup in style
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="WindowStyle" Value="None" />
<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=OverrideVisibility}" Value="false" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter TargetName="WindowCloseButton" Property="Visibility" Value="Visible" />
</MultiTrigger.Setters>
</MultiTrigger>
</ControlTemplate.Triggers>
Form xaml Setup:
<local:MyWindow x:Class="MyForm"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="500"
Height="500"
OverrideVisibility="True">
Your error is on this line:
Specifically, this is your error:
You probably have an error in your Output Window in Visual Studio that says something like:
Instead of that
Binding
, use the name/type of your customWindow
... something like this:Additionally, you said this:
It wouldn't... they are just for your use... they're not used by the Framework. If you want to monitor what values are going through a
DependencyProperty
, then you need to register aPropertyChangedCallback
event handler. You can find out more from the Custom Dependency Properties page on MSDN.UPDATE >>>
Ah, I just noticed the comments. You might still be able to do it if you can declare an Attached Property in an assembly that both your
Style
and your view have access to. If that's a possibility, then take a look at the Attached Properties Overview page on MSDN to find out how to do that.Finally, you can bind to an Attached Property like this:
This example was from the Property Path Syntax page on MSDN.