以编程方式设置 x:Uid 的值 [英] Set value of x:Uid programmatically

查看:25
本文介绍了以编程方式设置 x:Uid 的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 XAML 视图的代码隐藏文件中创建一个 AppBarButton.目前,我在 XAML 中定义了 AppBarButton,如下所示:

I am creating an AppBarButton in code behind file of XAML view. Currently, I have AppBarButton defined in XAML as below:

<AppBarButton x:Name="SelectVisitAppBarButton" x:Uid="AppBar_TransferVisit"  Margin="0,0,12,0" Icon="Bullets" Style="{StaticResource TransferAppBarButtonStyle}" IsEnabled="{Binding ScheduleViewVm.IsVisitSelectionEnable}" Click="SelectVisit_Click" />    

我想将此 XAML 转换为 C# 代码.以下是我到现在为止的代码.

I want to convert this XAML into C# code. Following is the code that I have till now.

AppBarButton SelectVisitAppBarButton = new AppBarButton();    
SelectVisitAppBarButton.Margin = new Thickness(0, 0, 12, 0);
SymbolIcon bulletSymbol = new SymbolIcon();
bulletSymbol.Symbol = Symbol.Bullets;
SelectVisitAppBarButton.Icon = bulletSymbol;
SelectVisitAppBarButton.Style = App.Current.Resources["TransferAppBarButtonStyle"] as Style;
SelectVisitAppBarButton.Click += SelectVisit_Click;
Binding b = new Binding();
b.Source = _viewModel.ScheduleViewVm.IsVisitSelectionEnable;
SelectVisitAppBarButton.SetBinding(Control.IsEnabledProperty, b);
Appbar.Children.Add(SelectVisitAppBarButton);

我唯一需要的是将 x:Uid="AppBar_TransferVisit" 转换为等效的 C# 代码.非常感谢您对此的任何帮助.

The only thing I am looking for is to convert x:Uid="AppBar_TransferVisit" into its equivalent C# code. Any help on this is highly appreciated.

谢谢,纳雷什·拉夫拉尼.

Thanks, Naresh Ravlani.

推荐答案

看来你实际上无法在 UWP 中以编程方式设置 x:Uid 属性:

It seems that you cannot actually set the x:Uid attribute programmatically in UWP:

如何设置控件 x:Uid 属性以编程方式用于 Metro 应用控件?

这是因为它是一个 XAML 指令而不是一个属性:

This is because it's a XAML directive rather than a property:

通过更改 x:uid 在visualstatemanager 中进行本地化?

您必须直接设置 AppBarButton 的相应属性,例如:

You will have to set the corresponding properties of the AppBarButton directly, e.g.:

AppBarButton SelectVisitAppBarButton = new AppBarButton();
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
var text = resourceLoader.GetString("SomeResource");
AppBarButton SelectVisitAppBarButton = new AppBarButton();
SelectVisitAppBarButton.Content = text;

这篇关于以编程方式设置 x:Uid 的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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