I’m trying to understand what does the markup extension for the x:Key attribute below do and what kind of markup extension is it?
<Window x:Class="App1.Window1" xmlns:dxg="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<DataTemplate x:Key="{dxg:Example ResourceKey=Example}">
<dxg:TextEdit Text="123/>
</DataTemplate>
</Window>
Thanks.
Well, that example won’t do anything – rather, it will fail, because isn’t a markup extension named
Examplein the WPF namespace.But if there were a markup extension named
Example, what it would do is instantiate anExampleMarkupExtensionobject, set itsResourceKeyproperty, and then call itsProvideValuemethod, which would return an object that would be used as the key for the item being added to the resource dictionary.Without more context, it’s hard to know what the example you’ve provided is intended to show. I’d guess that the concepts being demonstrated are a) that the key to a resource dictionary can be any object, not just a string, and b) that you can use a markup extension to generate that key. A real example:
which adds a
DataTemplatewith a key oftypeof(TextBox)to the resource dictionary.