WPF Adding a custom property in a control WPF Adding a custom property in a control wpf wpf

WPF Adding a custom property in a control


You can use the attached properties:

public class Extensions{    public static readonly DependencyProperty OverWidthProperty =        DependencyProperty.RegisterAttached("OverWidth", typeof(double), typeof(Extensions), new PropertyMetadata(default(double)));    public static void SetOverWidth(UIElement element, double value)    {        element.SetValue(OverWidthProperty, value);    }    public static double GetOverWidth(UIElement element)    {        return (double)element.GetValue(OverWidthProperty);    }}

Xaml:

xmlns:extensions="clr-namespace:NAMESPACE FOR Extensions class"<Trigger Property="IsMouseOver" Value="true">    <Setter Property="MinWidth" Value="{Binding Path=(extensions:Extensions.OverWidth), RelativeSource={RelativeSource Self}}"/></Trigger><Button extensions:Extensions.OverWidth="100" Width="10"/>


I used the Tag property, which works very well. I can write anything on Tag

For example (AXML) on a Button:

<Button x:Name="Btn80" Click="eventoClick" Tag="80">Casillero 80</Button>}

I can use a string field to add lists or values int, date, etc to then interpret and convert the string into anything.

**I used this solution, due to the need to add an ID field to a button.