tags:

views:

74

answers:

2

Hello, I have a big problem. I use additional controls for Wpf. One of them is Telerik RadWindow This control is already templated. Now I want to create custom Window with will inherit from RadWindow, and make custom template, eg. One base window will contains grid and two buttons, second base window will contain two grids (master - detail). The problem is that templates do not support inheritance. Perhaps is another way to template only the content of Winodow?

My code, that doesn't work (empty window appears, so template doesn't apply)

 <Style TargetType="{x:Type local:TBaseRjWindow}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:TBaseRjContent}">

                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">

                    <Grid Name="mGrid">

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition   />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition   />
                            <RowDefinition  MaxHeight="40" MinHeight="30"  />

                            <RowDefinition  MaxHeight="40" MinHeight="30"  />
                            <RowDefinition  Height="Auto"     />
                            <RowDefinition  MaxHeight="40" MinHeight="30" />
                        </Grid.RowDefinitions>

                        <telerik:RadGridView Margin="10,10,10,10" Name="grid" Grid.Row="0" Grid.Column="0"      VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  ScrollMode="Deferred"  AutoGenerateColumns="False"   Width="Auto"   >
                        </telerik:RadGridView>
                        <telerik:RadDataPager Grid.Row="1" Grid.Column="0"
      x:Name="radDataPager"
      PageSize="50"
      AutoEllipsisMode="None"
      DisplayMode="First, Previous, Next, Text"
      Margin="10,0,10,0"/>

                        <StackPanel Grid.Row="1" Grid.Column="0" Margin="5 5 5 5"  HorizontalAlignment="Left" Orientation="Horizontal" Height="20" Width="Auto" VerticalAlignment="Center"  >

                            <telerik:RadButton x:Name="btAdd"  Margin="5 0 5 0"   Content="Dodaj"  />
                            <telerik:RadButton x:Name="btEdit" Margin="5 0 5 0" Content="Edytuj"   />
                            <telerik:RadButton x:Name="btDelete" Margin="5 0 5 0" Content="Usun"   />
                        </StackPanel>

                        <StackPanel Name="addFields" Background="LightGray" Visibility="Collapsed" VerticalAlignment="Top"  Grid.Row="2"  Grid.Column="0" Width="Auto" Height="Auto" Orientation="Horizontal">
                            <GroupBox Header="Szczegoly" Margin="2 2 2 2" >
                                <Grid  VerticalAlignment="Top" DataContext="{Binding SelectedItem, ElementName=grid}" Name="_gAddFields" Margin="0 0 0 0"  Width="Auto" Height="Auto"  >
                                </Grid>
                            </GroupBox>
                        </StackPanel>

                        <StackPanel  Grid.Row="3" Grid.Column="0"  Margin="5 5 5 5" HorizontalAlignment="Right" Orientation="Horizontal" Height="25" Width="Auto" VerticalAlignment="Center"  >
                            <telerik:RadButton x:Name="btSave"  IsDefault="True" Width="60"  Margin="5 0 5 0" Content="Zapisz"    />
                            <telerik:RadButton x:Name="btOK" IsDefault="True"  Width="60" Margin="5 0 5 0"   Content="Akceptuj"  />
                            <telerik:RadButton x:Name="btCancel" IsCancel="True" Width="60" Margin="5 0 5 0" Content="Anuluj"    />
                        </StackPanel>
                    </Grid>

                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Please help

A: 

You could use the ContentTemplate for the Window. It is a DataTemplate that will be used to display the Content set on the Window.

Abe Heidebrecht
A: 

Thanks, I have orleady implement this, and work. but I have second problem. How to implement multiple contents. Eg. first ContentPresenter with additional icons, second ContentPresenter with additional buttons. I know how to do this with ControlTemplate. Now I have something like this:

<tN:TBaseRjWindow.ContentTemplate>
      <DataTemplate>
        <Grid Background="Azure" >
            <ContentPresenter ContentSource="{TemplateBinding Content}">
            </ContentPresenter>
        </Grid>
    </DataTemplate>

</tN:TBaseRjWindow.ContentTemplate>

And I would like to have something like this:

<tN:TBaseRjWindow.ContentTemplate>

    <DataTemplate   >
        <Grid Background="Azure" >
            <ContentPresenter ContentSource="{TemplateBinding AnotherContent1}">
            </ContentPresenter>
            <ContentPresenter ContentSource="{TemplateBinding AnotherContent2}">
            </ContentPresenter>
        </Grid>
    </DataTemplate>

</tN:TBaseRjWindow.ContentTemplate>

where AnotherContent will be DependencyProperty with returns Grid.

In XAML of my custom window I wont something like this:

    <tN:TBaseRjWindow.AnotherContent1>
<Grid>
        <StackPanel>
            <TextBlock Text="This is AnotherContent1"></TextBlock>
        </StackPanel>
</Grid>
</tN:TBaseRjWindow.AnotherContent>

Unfortunatelly this code doesn't work

mariusz