Ronny Witzgall
Ronny Witzgall

Reputation: 21

C# WPF App-wide DataTemplate works on one page but not on the same page in a Datagrid

I have written a DataTemplate in App.xaml.

<DataTemplate x:Key="PlayDVBViewer">
    <GroupBox Header="{x:Static properties:Resources.PlayInDVBViewer}" UseLayoutRounding="True" Margin="5">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <TextBlock Text="{x:Static properties:Resources.ChooseDVBViewer}" Margin="5" VerticalAlignment="Center"/>
            <ComboBox Grid.Row="1" ItemsSource="{Binding Clients.Items}" SelectedItem="{Binding Client}" SelectedValuePath="Name" DisplayMemberPath="Name" Margin="5" Padding="5" VerticalAlignment="Center"  Background="Transparent"/>
            <!--<Button Grid.Column="1" Grid.Row="1" x:Name="btnPlay" Click="BtnPlay_Click" Margin="5" Padding="5" VerticalAlignment="Center" Background="Transparent" Content="{x:Static properties:Resources.Playback}"/>-->
            <Button Grid.Column="1" Grid.Row="1" Command="{Binding BtnPlayClick}" Margin="5" Padding="5" VerticalAlignment="Center" Background="Transparent" Content="{x:Static properties:Resources.Playback}"/>
        </Grid>
    </GroupBox>
</DataTemplate>

The template works correctly in a page. But on the same page, in a DataGrid, it doesn't work. Why?

   <!--Wiedergabe Optionen -->
<GroupBox Header="{x:Static properties:Resources.Playback}" Grid.Row="1" Grid.Column="2" Margin="5">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <ContentPresenter Grid.Row="0" ContentTemplate="{StaticResource ResourceKey=PlayDVBViewer}" Content="{Binding}"/>
    </Grid>
</GroupBox>

<DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <Grid>
                        <!-- Detail Grid mit den Buttons zum Abspielen -->
                        <Grid Grid.Row="0">
                            <StackPanel Orientation="Horizontal">
                                <GroupBox Header="{x:Static properties:Resources.Picture}" MinWidth="120" Margin="5">
                                    <Image Height="64" Source="{Binding ImagePath, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:PageAufnahmen}}}" Margin="5"/>
                                </GroupBox>
                                <ContentPresenter ContentTemplate="{StaticResource PlayDVBViewer}"/>
                            </StackPanel>
                        </Grid>
                    </Grid>
                </DataTemplate>
</DataGrid.RowDetailsTemplate>

Upvotes: 1

Views: 32

Answers (1)

Ronny Witzgall
Ronny Witzgall

Reputation: 21

Ok, I have found the error.

If you use ContentPresenter in the DataTemplate of a grid. The binding will bind to the selected item. The solution is, use the same binding, like the image in the last box, see my post above.

Upvotes: 1

Related Questions