来自静态资源的Wpf窗口标题

来自静态资源的Wpf窗口标题,wpf,dictionary,window,title,Wpf,Dictionary,Window,Title,我正在使用资源字典进行本地化,我在wpf中有以下代码: <Window x:Class="RWIS_WPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="RWIS" Height="500" Width="800" MinHeight

我正在使用资源字典进行本地化,我在wpf中有以下代码:

<Window x:Class="RWIS_WPF.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="RWIS" Height="500" Width="800" MinHeight="500" MinWidth="800">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Localizations/Dictionary.EN.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
但它不起作用,因为资源是在title调用它之后定义的。当我尝试运行它时,它会给我错误

System.Windows.Markup.XamlParseException发生消息=“提供” “System.Windows.StaticResourceExtension”上的值引发了异常 行号“6”和行位置“9”

它在添加资源后用于标题、文本

我曾尝试用c代码调用它,但没有成功。
我知道有选择:

<Window.Title></Window.Title>


但是没有像text或value这样的参数,我可以把
text=“{StaticResource IT\u is\u WORKING}”

放在哪里呢?只要使用
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>
xmlns:System=“clr命名空间:系统;程序集=mscorlib”
...
一些头衔
...

StaticResource
在将BAML(已编译的XAML)加载到内存时应用,它从上到下解析XAML,并且由于您的资源尚未创建,因此在加载XAML时抛出错误

相反,请尝试使用
DynamicResource
,您可以说这是一个延迟加载的版本。它将表达式对象指定给目标属性。这将推迟查找资源,直到运行时需要它

阅读此内容以进一步澄清-


我知道我现在是“那个家伙”,但。。。这应该是公认的答案
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>
<Window Title="{DynamicResource IT_WILL_WORK}"/>