我正在将一个应用程序从 Windows 8 迁移到 UWP。该应用程序使用字符串资源进行本地化。 在 Windows 8 中,我曾经这样做来本地化 AppBar 按钮:
<Style x:Key="SkipAheadAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource AppBarButtonStyle}">
<Setter Property="AutomationProperties.AutomationId" Value="SkipAheadAppBarButton"/>
<Setter x:Uid="Step" Property="AutomationProperties.Name" Value=".skip"/>
<Setter Property="Content" Value=""/>
</Style>
然后我会得到一个字符串“Step.Value”。由于某些原因,这在 Visual Studio 2017 中的 UWP 项目中不起作用。按钮显示“.skip”而不是 Resources.resw 中 Step.Value 的实际值。
更简单 <Run x:Uid="App" Text=".Rob"/>
工作没有任何问题。
最佳答案
我们不能使用 x:Uid
在Setter
.
Use x:Uid to identify an object element in your XAML. Typically this object element is an instance of a control class or other element that is displayed in a UI.
更多信息请引用x:Uid directive的备注.
您应该能够添加 x:Uid
在Button
.
例如:
<Button x:Uid="MyButton" AutomationProperties.Name="AddToIndexButton" Content="Button"></Button>
您应该能够设置 MyButton.AutomationProperties.Name
到 Name
和 YourValue
到 Value
Resources.resw 的。
我还测试了 <Run x:Uid="App" Text=".Rob"/>
,它会抛出异常。如果你可以在 UWP 中使用它,你能给我们一个示例吗?
关于localization - 在 UWP Style Setter 中使用字符串资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44092881/