Hi Community,
I've created an usercontrol 'Splitter'.
xaml looks like this:
<UserControl x:Class="DesktopApp.UserControls.Splitter"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Border x:Name="oBorder">
<Border.Effect>
<DropShadowEffect x:Name="oShadow" />
</Border.Effect>
</Border>
</UserControl>
I want to access some Properties of the oBorder and oShadow-Childs.
For example i want to set the Color-Property of the Child "oBorder" like this:
<uc:Splitter x:Name="oSplitter" SplitterColor="Orange"></uc:Splitter>
where uc is defined as following:
xmlns:uc="clr-namespace:DesktopApp.UserControls"
So I've put a DP called 'SplitterColor' into my usercontrol.
public Brush SplitterColor
{
get { return (Brush)GetValue(SplitterColorProperty); }
set { SetValue(SplitterColorProperty, value); }
}
I've defined a default value 'Brushes.White'
public static readonly DependencyProperty SplitterColorProperty =
DependencyProperty.Register("SplitterColor", typeof(Brush), typeof(Splitter), new PropertyMetadata(Brushes.White, OnSplitterColorChanged));
This code changes the Color-Property of by oBorder Child. In this example dNewBackgroundColor will be an Orange brush.
private static void OnSplitterColorChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
{
Brush dNewBackgroundColor = eventArgs.NewValue as Brush;
Splitter oThis;
if (dNewBackgroundColor != null)
{
oThis = sender as Splitter;
if (oThis != null)
{
oThis.oBorder.Background = dNewBackgroundColor;
}
}
}
It works fine !
But if i define my control as the following:
<uc:Splitter x:Name="oSplitter" SplitterColor="White"></uc:Splitter>
or
<uc:Splitter x:Name="oSplitter"></uc:Splitter>
my programm will not step into my OnSplitterColorChanged-handler. So my color will not be set to my oBorder Child.
What's the default way to set the default value of my dependency-property to my child ?
Jeff