Reputation: 55
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.
Upvotes: 0
Views: 480
Reputation: 96702
Well, that example won't do anything - rather, it will fail, because isn't a markup extension named Example
in the WPF namespace.
But if there were a markup extension named Example
, what it would do is instantiate an ExampleMarkupExtension
object, set its ResourceKey
property, and then call its ProvideValue
method, 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:
<DataTemplate x:Key="{x:Type TextBox}">
which adds a DataTemplate
with a key of typeof(TextBox)
to the resource dictionary.
Upvotes: 2
Reputation: 166
usually the x:Key attribute allows you to reference a resource by key, in this case as the template is not within a ResourceDictionary I'm not sure it has any purpose!
Hope this helps!
Upvotes: 0