我有一个具有以下用户控件的XBAP应用程序:
<UserControl x:Class="XXX.UsersGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="Auto" Width="Auto">
<UserControl.Resources>
<DataTemplate x:Key="UpArrowUsers">
<DockPanel>
<TextBlock Text="xxUser" x:Name="upArrowUsersHeader" HorizontalAlignment="Center"></TextBlock>
<Path x:Name="arrow" StrokeThickness = "1" Fill= "gray" Data= "M 5,10 L 15,10 L 10,5 L 5,10"/>
</DockPanel>
</DataTemplate>
</UserControl>
...现在我想从resx文件中获取字符串"xxUser“,该文件作为资源嵌入到应用程序中,我如何实现这一点?
发布于 2009-03-20 12:37:41
我不知道这是否可以直接在XAML中完成,但是如果您在ResourceManager周围编写自己的包装器类并使用它。请注意,该类继承自TextBlock:
public class ResourceContentTextBlock : TextBlock
{
public string ResourceName
{
set
{
this.Text = Properties.Resources.ResourceManager.GetString(value);
}
}
}然后,您可以在您的XAML中使用ResourceContentTextBlock,否则就可以使用TextBlock:
<Window x:Class="WpfApplication3.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:client="clr-namespace:WpfApplication3"
>
<client:ResourceContentTextBlock ResourceName="String1" />
</Window>https://stackoverflow.com/questions/665764
复制相似问题