2017-12-31 89 views
0

私はGridを持っています。GridView.xaml.csのコードビハインドからすべてのセルに入れたいと思っています。問題は、私はC#で、それで何かをバインドするDataTemplateで私が持っているすべてのthatsDataTemplateを使用したC#のUWP GridView

DataTemplate Template= new DataTemplate(); 
GridView gridView = new GridView(); 
gridView.ItemsSource = book; 

GridViewを作成する方法を知らないということです。ヘルプは、私が.xaml.csにコードビハインドからのすべてのセルにGridViewコントロールを配置する

J.

答えて

0

を高く評価しています。

App.xamlファイルでDataTemplateを次のように作成することができます。

<Application.Resources> 
    <ResourceDictionary> 
     <DataTemplate x:Key="template"> 
      <StackPanel> 
       <TextBlock Text="{Binding }"/> 
      </StackPanel> 
     </DataTemplate> 
    </ResourceDictionary> 
</Application.Resources> 

コードビハインドで使用してください。

private void SetUpUI() 
{ 
    var gridView = new GridView(); 
    //DataTemplate usage. 
    gridView.ItemTemplate = (DataTemplate)App.Current.Resources["template"]; 
    gridView.ItemsSource = new List<string> { "fas", "fasd", "fasf" }; 
    RootLayout.Children.Add(gridView); 
} 
+0

これは完璧に機能しました。ありがとう –

関連する問題