question as above
Dependency properties don't really have default values. If a dependency property doesn't have a local value, it will obtain its value either through value inheritance or through coercion, depending on how the property has been implemented.
You can't really get rid of the property's local value in XAML - that would require you to call ClearValue
on the property, and there's no way to find the object and call a method on it declaratively. But as long as the property's getting its value through value inheritance (instead of value coercion) - you can accomplish fundamentally the same thing by binding the property to the property it's inheriting from on the appropriate ancestor
For instance, here's a style you'd use to create a ListBox
that sets the foreground color of all items that aren't selected:
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Foreground" Value="Red"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter
Property="Foreground"
Value="{Binding
RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox},
Path=Foreground}" />
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
This basically explicitly implements value inheritance through binding. It does mean that the ListBoxItem.Foreground
property now has a local value, and that whenever you change the Foreground
property on the ListBox
it's binding that updates the ListBoxItem.Foreground
and not the dependency-property system. This might actually matter if you have hundreds of thousands of items in your ListBox
. But in most real-world cases, you'll never notice the difference.
http://social.msdn.microsoft.com/Forums/en/wpf/thread/bb601bcb-83c0-426a-8bc8-ae088b4ebc28
hi i manage to solve my problem... thanks