问题
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