I have a resource dictionary defined in my prism assembly that contains data templates. My goal is to have the DataType=""
attribute defined on them for type-safety while also storing my x:Key=""
strings in a separate .resx file for re-use. I found this stackOverflow answer that discusses the use of using {x:Static }
for accessing the text, with a much more verbose approach required to not have them be accessed in this manner.
Unfortunately, it appears that using the method above methods together cause the x:Key
to default to nameof(DataType)
, which causes issues when multiple types are defined with different keys.
Here is an example of the scenario:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Namespace.Class"
xmlns:resources="clr-namespace:Namespace">
// Key is the value of the .resx string "MyResxString"
<DataTemplate x:Key="{x:Static resources:Text.MyResxString}"/>
// Key is "myClass"
<DataTemplate DataType="{x:Type myClass}"/>
// Key is "example"
<DataTemplate x:Key="Example" DataType="{x:Type myClass}" />
// Key is unexpectedly "myClass" and my static string is ignored in the key attribute
<DataTemplate x:Key="{x:Static resources:Text.MyResxString}"
DataType="{x:Type myClass}"/>
</ResourceDictionary>
Is this an intended result from this binding or is something amiss here? Is there an alternative approach to doing this same thing? (I understand .resx isn't the best approach in the first place, but it's our standard)