Reputation: 2080
I have this DataGrid
:
<DataGrid x:Name="ButtonsDataGrid" Grid.Row="1" Margin="5,5,0,0"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Background="Transparent" HeadersVisibility="None"
BorderThickness="0" BorderBrush="Transparent">
<DataGridTemplateColumn Header="user_buttons">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<userButtons:GuestButtons/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid>
and the XAML UserControl
that I need to put inside of that DataTemplate
:
<UserControl x:Class="HP_hf_shop.BrowseButtons.GuestButtons"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:HP_hf_shop.BrowseButtons"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Button Template="{DynamicResource TileTemplate}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="5*"/>
</Grid.ColumnDefinitions>
<Path Data="M1.5,38.001 L10.666,38.001 10.666,38.005341 C10.666,38.011758 10.666,38.015 10.666,38.015 L57.666903,38.001107 67.909877,38.001 67.909877,81.667664 1.5,81.667664 z M34.188718,1.5000001 C46.680964,1.4988451 57.432162,7.8204405 57.710986,14.7386 57.917159,19.854203 57.674712,37.439694 57.667087,37.987992 L57.666903,38.001 10.666,38.001 10.666,37.976643 C10.665999,37.189652 10.665995,24.468745 10.666321,16.211438 10.666653,7.8482163 20.950168,1.501225 34.188718,1.5000001 z"
Style="{DynamicResource MimicVectorStyle}" Stretch="Fill" StrokeThickness="3" d:LayoutOverrides="LeftMargin, RightMargin, TopMargin, BottomMargin"
Margin="5,2,5,2" Grid.Column="0"/>
<Label Grid.Row="1" Grid.Column="1" VerticalAlignment="Center"
HorizontalContentAlignment="Left" VerticalContentAlignment="Center"
Content="REGISTER" FontSize="30" FontFamily="CenturyGothicRegual"
Margin="0,0,0,0" Style="{DynamicResource MimicLabelStyle}">
</Label>
</Grid>
</Button>
</Grid>
The problem is that nothing appears inside of the DataGrid
row even if the button
inside my UserControl
is visible inside the designer. Later on this will have to be dynamic, that's the reason I don't just type the buttons inside of the row I mentioned as I'll have a list of buttons for guests, admins and customers. So again, how to make that XAML UserControl
's contents appear inside a row of my DataGrid
?
I added
HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
VerticalAlignment="Stretch" VerticalContentAlignment="Stretch"
inside the DataGrid
but the problem persists.
The code compiles and runs without any errors.
I created a whole new solution and copy-pasted the XAML code from this MSDN article, nothing changed. It doesn't give their results even when I run the project. I'm on Visual Studio 2015, shall I reinstall?? :D
Upvotes: 1
Views: 57
Reputation: 35679
I copied the sample and to make it work I fixed two issues:
1) DataGrid doesn't have ItemsSource set. How to fix:
xaml:
<DataGrid x:Name="ButtonsDataGrid"
ItemsSource="{Binding Path=???-some-collection-from-DataContext}" ...
or code:
ButtonsDataGrid.ItemsSource = someCollection;
2) with ItemsSource set I got XamlParseException. DataGridTemplateColumn should be added to DataGrid.Columns, not directly to DataGrid.
<DataGrid.Columns>
<DataGridTemplateColumn Header="user_buttons">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<wpfDemos:GuestButtons/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
Upvotes: 1