|
|
<div id="cnblogs_post_body">类似Winform的搞法,可以把资源放到Resources.resx中。
1.字符串
打开这个编辑器后,输入Name和Value就可以了。

CS代码里面,很简单的调用:
var title = WpfResource2.Properties.Resources.IDS_TEST_TITLE;
如果要用在XAML中,需要把Access Modifier改为public,原来是Internal。

XAML如下:
<div class="cnblogs_code">1 <Window x:Class="WpfResource2.MainWindow"2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"4 xmlns:res="clr-namespace:WpfResource2.Properties"5 Title="MainWindow" Height="350" Width="525">6 <Grid>7 <TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Text="{x:Static res:Resources.IDS_TEST_TITLE}">8 9 </TextBlock> |
|