在 Metro 中获取 TextBlock 的 x:Uid 属性 [英] Get x:Uid propertry of TextBlock in Metro

查看:28
本文介绍了在 Metro 中获取 TextBlock 的 x:Uid 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在地铁应用程序中获得 x:uid 控制属性.

Is there any way to get x:uid property of control in metro apps.

            <Button x:Name="ViewPanelButton" 
                    Grid.Column="3" 
                    Grid.Row="0" 
                    x:Uid="s_View" 
                    VerticalAlignment="Bottom" 
                    Margin="5,0,0,5" 
                    HorizontalAlignment="Center" 
                    Style="{StaticResource MainPageButtonStyle}" 
                    Click="ViewPanelButton_Click" 
                    Height="22" 
                    Width="Auto" />

我想从后面的代码中获取这个 x:Uid 属性.它是 WPF 中的财产,但不是地铁中的财产.有没有办法在地铁应用中获得这个属性?

I want to get this x:Uid property from code behind. It is property in WPF but not in metro. Is there any way to get this property in metro apps ?

推荐答案

很遗憾,我已向平台团队确认您(目前)还不能这样做.

With regret, I have confirmed with the platform team that you cannot do this (yet).

但是,您可以手动设置默认语言.

You can, however, manually set the default language.

public void Setup()
{
    var r = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView();
    r.QualifierValues.MapChanged += QualifierValues_MapChanged;
}

public void Cleanup()
{
    var r = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView();
    r.QualifierValues.MapChanged -= QualifierValues_MapChanged;
}

void QualifierValues_MapChanged(Windows.Foundation.Collections.IObservableMap<string, string> sender, Windows.Foundation.Collections.IMapChangedEventArgs<string> @event)
{
    // you can fetch the default, and test if you need change
    string d;
    var m = Windows.ApplicationModel.Resources.Core.ResourceManager.Current.DefaultContext.QualifierValues;
    if (!m.TryGetValue("Language", out d))
        return;

    // you can set your own or use the first (default)
    var l = Windows.System.UserProfile.GlobalizationPreferences.Languages.First();
    Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = l;
}

祝你好运!

这篇关于在 Metro 中获取 TextBlock 的 x:Uid 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆