Hi,
These properties do not exist in the UserControl class, so you cannot bind to them without defining them first. E.g. add this to Mybutton.xaml.cs:
static public DependencyProperty StrokeProperty = DependencyProperty.Register(
"Stroke", typeof(Brush), typeof(Mybutton), new PropertyMetadata(Brushes.Black));
public Brush Stroke
{
get { return (Brush)GetValue(StrokeProperty); }
set { SetValue(StrokeProperty, value); }
}
and then you will be able to set button.Stroke instead of button.Rectangle.Stroke in the code-behind, using the binding expression you already have in the xaml.
Also for such type of control you would be better off deriving from Control instead of UserControl, and defining the appearance using a control template instead of user-control xaml. Then the binding expressions would be much simpler, e.g.:
<Rectangle Stroke="{TemplateBinding Stroke}" />
A different way to simplify them while still deriving from UserControl is to set DataContext = this in control constructor. Then you can skip the RelativeSource part and it will look like this:
<Rectangle Stroke="{Binding Stroke}" />
I hope that helps,
Stoyan