Nar*_*ani 5 c# xaml windows-mobile winrt-xaml uwp
我在XAML视图的代码隐藏文件中创建一个AppBarButton.目前,我在XAML中定义了AppBarButton,如下所示:
<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" />
Run Code Online (Sandbox Code Playgroud)
我想将此XAML转换为C#代码.以下是我到目前为止的代码.
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);
Run Code Online (Sandbox Code Playgroud)
我唯一想要的是将x:Uid ="AppBar_TransferVisit"转换为其等效的C#代码.对此的任何帮助都非常感谢.
谢谢,Naresh Ravlani.
您似乎无法在UWP中以编程方式实际设置x:Uid属性:
如何以编程方式为metro应用程序控件设置控件x:Uid属性?
这是因为它是一个XAML指令而不是属性:
通过更改x:uid在visualstatemanager中进行本地化?
您必须直接设置AppBarButton的相应属性,例如:
AppBarButton SelectVisitAppBarButton = new AppBarButton();
var resourceLoader = new Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
var text = loader.GetString("SomeResource");
AppBarButton SelectVisitAppBarButton = new AppBarButton();
SelectVisitAppBarButton.Content = text;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1334 次 |
| 最近记录: |