Note: UserControl is not same as Control in which we are using Templates..
UserControl just holds other controls and wrap them.
- Create DP in UserControl.xaml.cs file same as of its child control.
- Bind this new DP with the inner control's DP
- Now you could use DP of inner control out side of UserControl
Here attached a sample which demonstrates this.
MyUserControl holds a slider and we are going to expose the Value DP of this through MyUserControl.
So add Value DP to MyUserControl and Bind that to Value DP of inner slider.
public partial class MySlider : System.Windows.Controls.UserControl
{
public MySlider()
{
InitializeComponent();
}
public static readonly DependencyProperty ValueProperty=DependencyProperty.Register("Value",typeof(double),typeof(MySlider));
public double Value
{
get
{
return (double)GetValue(MySlider.ValueProperty);
}
set
{
SetValue(MySlider.ValueProperty, value);
}
}
}
MyUserControl.XAML
<UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="BindingUserControl.MySlider"
Width="Auto" Height="Auto" x:Name="UserControl" >
<Grid>
<Slider Name="sldr" Value="{Binding Path=Value, ElementName=UserControl, Mode=TwoWay}" Width="100" />
</Grid>
</UserControl>
Sample