简体   繁体   中英

How to set AppBarButton text with String resource using XAML

Is there a way to set a string resource as the text for an AppBarButton rather than having to do it programmatically? The method used below doesn't work for some reason.

<Page>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <CommandBar>
            <CommandBar.Content>
                <Button 
                    Style="{StaticResource NavigationBackButtonNormalStyle}" 
                    Name="BackButton" 
                    VerticalAlignment="Top" 
                    Click="Back_Click"/>
            </CommandBar.Content>

            <AppBarButton Name="HelloWorld" x:Uid="HelloWorld">
                <AppBarButton.Icon>
                    <FontIcon Glyph="&#xE110;"/>
                </AppBarButton.Icon>
            </AppBarButton>
        </CommandBar>
        <Frame Name="MyFrame"/>
    </Grid>
</Page>

The reason why your code didn't work, maybe related to the Resources.resw file. Fisrt as Richard Zhang - MSFT said, you need to create a Strings folder, and create the corresponding localize folder. 在此处输入图像描述

In Resources.resw , new a key/value called HelloWorld.Label , set value to Hello World!

在此处输入图像描述

Be attention, we are setting the AppBarButton 's Label . If you set the key to "HelloWorld", then nothing happens. 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM