Search code examples
wpfxamlstaticresourcemarkup-extensions

StaticResource vs StaticResourceExtension syntax


What's the difference between.

<TextBox Text="{local:BindingResourceExtension MyBinding}" >
    <TextBox.Style>
        <StaticResourceExtension  ResourceKey="style" />
    </TextBox.Style>
</TextBox>

and

<TextBox Text="{local:BindingResourceExtension MyBinding}" Style="{StaticResource style}"/>

Which should be preferred in XAML?


Solution

  • There is no difference. The curly brace syntax is designed specifically so you can use markup extensions within attribute values without having to resort to specifying the properties as child elements like in the first example. So, naturally, the curly brace syntax is preferred in those situations.