WPF binding: how to bind data to a grid?

I created an Account class.
Then I created another ReorderWindowController class that has a SelectedAccount field / property of type Account .

Finally, I wrote a ReorderWindow WPF window ReorderWindow file:

 <Window ... <Window.Resources> <contollers:ReorderWindowController x:Key="WindowController" /> <DataTemplate DataType="{x:Type entities:Account}"> <Grid Width="140" Height="50" Margin="5"> <TextBlock Text="Some awesome text" /> <TextBlock Text="{Binding Name}" /> <TextBlock Text="Even more awesome text" /> </Grid> </DataTemplate> </Window.Resources> <Grid> <Grid Name="AccountGrid" DataContext="{Binding Source={StaticResource ResourceKey=WindowController}, Path=SelectedAccount}"> </Grid> </Grid> </Window> 

When I run my code, AccountGrid nothing. What for? How to bind object data to a Grid and how can I use my data template? Thank you

+4
source share
1 answer

Instead of Grid, use ContentPresenter as follows:

 <Grid> <ContentPresenter Name="AccountGrid" Content="{Binding Source={StaticResource ResourceKey=WindowController}, Path=SelectedAccount}"> </ContentPresenter> </Grid> 
+7
source

Source: https://habr.com/ru/post/1332821/