Wpf window title from static resource

旧城冷巷雨未停 提交于 2019-12-05 11:07:52

Just use the more verbose definition of StaticResource:

xmlns:System="clr-namespace:System;assembly=mscorlib"

...

<Window.Resources>
    <System:String x:Key="Title">Some Title</System:String>
    ...
</Window.Resources>
<Window.Title>
    <StaticResource ResourceKey="Title" />
</Window.Title>
Rohit Vats

StaticResource are applied at the time of loading of BAML (compiled XAML) into memory and it parses XAML from top to bottom and since your resource haven't created yet, it throws error while loading of XAML.

Instead, try using DynamicResource which is lazy loaded version you can say. It assigns an expression object to target property. This defers looking up the resource until it is needed at runtime.

Read this for further clarification - StaticResource V/S DyanamicResource.

<Window Title="{DynamicResource IT_WILL_WORK}"/>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!