-1

I've just started learning WPF but I can't seem to figure out how to combine two or more string static resources in XAML. I have two static resources, UntitledFileName ("Untitled") and ApplicationName ("SomeAppName"). The third resource, DefaultWindowTitle, should be composed of the aforementioned resources, and should contain the value "Untitled - SomeAppName". How should I specify the two static resources when defining DefaultWindowTitle?

<sys:String x:Key="UntitledFileName">Untitled</sys:String>
<sys:String x:Key="ApplicationName">SomeAppName</sys:String>
<sys:String x:Key="DefaultWindowTitle">...</sys:String>
3
  • No way. XAML is a declarative language, not an algorithmic one. You can convert both strings to one by setting the DependencyProperty to MultiBining using StringFormat. Commented Dec 3, 2022 at 14:42
  • 1
    I would suggest two runs in a textblock. Text of each run set to a staticresource and hence appear concatenated in one textblock. A textblock is the closest equivalent to a label in other tech. Commented Dec 3, 2022 at 15:30
  • I was planning to use "DefaultWindowTitle" as the window's title. Commented Dec 4, 2022 at 10:39

1 Answer 1

0

I was planning to use "DefaultWindowTitle" as the window's title.

Perhaps this implementation will suit you:

<Window.Title>
    <MultiBinding StringFormat="{}{0} - {1}">
        <Binding Source="{StaticResource UntitledFileName}"/>
        <Binding Source="{StaticResource ApplicationName}"/>
    <MultiBinding>
</Window.Title>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.