You can specify a value to an attribute using curly braces ‘{}’ is called as Markup Extensions in XAML. The most commonly used markup extensions in WPF are Binding, StaticResource, DynamicResources, RelativeSource, TemplateBinding etc. These all markup extensions are default provided by WPF. If you want you can create your own Markup Extension you can achieve it by deriving MarkupExtension class. Nested Markup Extensions also possible in XAML.
<Window.Resources>
<Style x:Key="MyStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red" />
</Style>
</Window.Resources>
<StackPanel>
<Button Content="Click Me!" Style="{StaticResource MyStyle}" />
</StackPanel>
In above example Style attribute of Button uses StaticResource Markup Extension.
Is the custom markup extension and what we talking above are same. ??
ReplyDeleteIn this post no custom markup extensions used. You can create your own markup extension as per your requirement,
Delete