Attached Property in WPF
Attached Property :
An attached property is a special form of dependency property that can effectively be attached to arbitrary objects.
<StackPanel TextElement.FontSize=”30” TextElement.FontStyle=”Italic”
Orientation=”Horizontal” HorizontalAlignment=”Center”>
<Button MinWidth=”75” Margin=”10”>Help</Button>
<Button MinWidth=”75” Margin=”10”>OK</Button>
</StackPanel>
StackPanel panel = new StackPanel();
TextElement.SetFontSize(panel, 30);
TextElement.SetFontStyle(panel, FontStyles.Italic);
Another Ex:
public static void SetRow(UIElement element, int value)
{
if (element == null)
{
throw new ArgumentNullException(...);
}
element.SetValue(Grid.RowProperty, value);
}
Here’s an example that positions an element in the first row of a Grid using code:
Grid.SetRow(txtElement, 0);
Another Ex:
ComboBox comboBox = new ComboBox();
comboBox.SetValue(PasswordBox.PasswordCharProperty, "*");