简体   繁体   中英

C# WPF static resource containing other static resources

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM