包含此
xmlns:system="clr-namespace:System;assembly=mscorlib"
有system:string
這樣的資源。
<Window.Resources>
<system:String x:Key="GreetingText">Hello</system:String>
</Window.Resources>
,並用它在XAML爲
<TextBlock Text="{StaticResource GreetingText}" />
並在代碼中使用它身後,
string s = (string)objectofMainWindow.Resources["GreetingText"];
編輯:回答你的評論
它的這種方式。資源字典裏面Window.Resources
<Window
xmlns:system="clr-namespace:System;assembly=mscorlib"
Your Rest namespaces
/>
<Window.Resources>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ATTFamilyMap.strings">
<system:String x:Key="GreetingText">Hello</system:String>
</ResourceDictionary>
</Window.Resources>
Your Code
</Window>
簡單而簡單:) –