问题
Hello I want to localize text below standard AddAppBarButton
<Style x:Key="AddAppBarButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource AppBarButtonStyle}">
<Setter Property="AutomationProperties.AutomationId" Value="AddAppBarButton"/>
<Setter Property="AutomationProperties.Name" Value="Add"/>
<Setter Property="Content" Value=""/>
</Style>
I've tried in Resource filead add something like
ButtonId.AutomationProperties.Name = value
But it doesn not work. I get errors when app starts. How can I trasnlate this property ?
回答1:
Why not put the translation strings in resource files and let XAML parser do the work?
You need to create a folder in your project matching the locale name and put a resw file inside it, e.g sl-SI\Resources.resw
.
Add x:Uid
attribute to XAML elements to name them:
<Button x:Uid="AppBarButton" Style="{StaticResource AddAppBarButtonStyle}" />
Now just name the resource strings appropriately so that the XAML parser will find them. The pattern is UidName.PropertyName
, e.g. Button.Content
. In the case of AppBar buttons the syntax is a little more complex because of attached properties:
AppBarButton.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name
回答2:
You could try AutomationProperties.SetName(ButtonId, value);
来源:https://stackoverflow.com/questions/13572273/how-to-translate-sign-under-appbar-buttom