Get x:Uid propertry of TextBlock in Metro

谁说我不能喝 提交于 2019-12-11 12:52:19

问题


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" />

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 ?


回答1:


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;
}

Best of luck!



来源:https://stackoverflow.com/questions/20349220/get-xuid-propertry-of-textblock-in-metro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!