Mam kilka dependency propertisów w kontrolce a zmiany są sygnalizowane tylko dla jednego (PathData)
public partial class PathControl : UserControl, INotifyPropertyChanged
{
/////////////////////////////////////////////////////////////////////////////////
public static readonly DependencyProperty ViewboxWidthProperty =
DependencyProperty.Register("ViewboxWidth", typeof(double),
typeof(PathControl), new PropertyMetadata((double)48, SOnPropertyChanged));
public double ViewboxWidth
{
get { return (double)GetValue(ViewboxWidthProperty); }
set { SetValue(ViewboxWidthProperty, value); }
}
public static readonly DependencyProperty ViewboxHeightProperty =
DependencyProperty.Register("ViewboxHeight", typeof(double),
typeof(PathControl), new PropertyMetadata((double)48, SOnPropertyChanged));
public double ViewboxHeight
{
get { return (double)GetValue(ViewboxHeightProperty); }
set { SetValue(ViewboxHeightProperty, value); }
}
/////////////////////////////////////////////////////////////////////////////////
public static readonly DependencyProperty PathDataProperty =
DependencyProperty.Register("PathData", typeof(string),
typeof(PathControl), new PropertyMetadata("", SOnPropertyChanged));
public string PathData
{
get { return (string)GetValue(PathDataProperty); }
set { SetValue(PathDataProperty, value); }
}
private static void SOnPropertyChanged(
DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var control = sender as PathControl;
var property = e.Property;
switch (property.Name)
{
case "PathData":
var converter = TypeDescriptor.GetConverter(typeof(Geometry));
control.path.Data = (Geometry)converter.ConvertFrom(e.NewValue);
break;
}
}
}
Użycie:
<Grid>
<TextBlock ... />
<controls:PathControl Width="80" Height="80"
ViewboxWidth="48"
ViewboxHeight="48"
PathStyle="White"
Margin="107,193,113,27" PathData="M3.15,5.27L8.13,10.26L2.15,14V16L10.15,13.5V19L8.15,20.5V22L11.65,21L15.15,22V20.5L13.15,19V15.27L18.87,21L20.15,19.73L4.42,4M13.15,9V3.5A1.5,1.5 0 0,0 11.65,2A1.5,1.5 0 0,0 10.15,3.5V7.18L17.97,15L21.15,16V14L13.15,9Z"
/>
</Grid>