Here’s my ‘sample code’, including what I’m trying to do. Obviously, it doesn’t work at the moment, but is there any way I can make it work?
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
>
<System:String x:Key="ProductName">Foo</System:String>
<System:String x:Key="WindowTitle">{ProductName} + Main Window</System:String>
</ResourceDictionary>
The only way to add a computed string to a ResourceDictionary in this way is to create a
MarkupExtension. YourMarkupExtensionwould be used like this:This assumes you have created a
MarkupExtensionsubclass in your “local” namespace namedMyStringFormatterExtensionthat has properties named “StringFormat”, “Arg1”, “Arg2”, etc, and has aProvideValue()method that does the obvious.Note that as Aran points out, a
BindingusingStringFormatterwould be a more common way to achieve the same effect, and is generally the better design. The tradeoff is it would not allow the result to be used as part of aResourceDictionary.