2016-12-29 3 views
3

XAMLビューのコードビハインドファイルでAppBarButtonを作成しています。 現在、私は以下のようにXAMLでAppBarButtonを定義している:xの値をプログラムで設定します。

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

私はC#のコードには、このXAMLを変換したいです。以下は私が今まで持っているコードです。それと同等のC#コードにUID = "AppBar_TransferVisit":

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を変換することです。これに関する助言は高く評価されます。

ありがとう、 Naresh Ravlani。

答えて

4

あなたが実際にXを設定することができないようだ。UWPでプログラムuid属性を:

How to set control x:Uid attribute programmatically for a metro app control?

それがXAMLディレクティブではなく、財産ですので、これは次のとおりです。

Doing localization in visualstatemanager by changing x:uid?

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

私はUWP-XAMLプラットフォームチームにx:UIDにプログラム的にアクセスしていると話していることを確認することはできません。あなたが私に尋ねるなら、これは欠点です。しかし、現時点ではそれが何であるかです。 :)

+0

私はこれを見つけることができる任意のドキュメントリンクを共有できる場合に役立ちます。 –

1

XamlReaderを使用してxamlからボタンをロードする方法があります。

Button btn = (Button)XamlReader.Load("<Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Uid='btnSubmit' Margin='5,0,0,0'/>"); 
btn.OtherProperty = xxxx 
関連する問題