Click here to Skip to main content
15,885,878 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
Hello,

I have created a custom control Library called Base_Dialog and I built in Base_Dialog ---BaseDlg
like this:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Base_Dialog
{
    public class BaseDlg : Window
    {
        static BaseDlg()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(BaseDlg), new FrameworkPropertyMetadata(typeof(BaseDlg)));
        }
    }
}



and in Generic.xaml
XML
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Base_Dialog"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
    <Style TargetType="{x:Type local:BaseDlg}" >
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:BaseDlg}">
                    <Grid Background="Salmon">
                        <TextBlock Text="kdjdfg"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>


and I wrote the following code in the AssemblyInfo.cs file:
<br />
[assembly: XmlnsDefinition("http://schemas.sheva.com/winfx/2006/xaml/presentation", "Base_Dialog")]

then open wpfapplication name((wpf))and add references Project ((Base_Dialog))

xaml code is:
XML
<local:BaseDlg x:Class="wpf.Box"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="http://schemas.sheva.com/winfx/2006/xaml/presentation"
        Title="Box" Height="300" Width="300">
    <Grid>
        <Button Content="enas" Height="30" Width="30" HorizontalAlignment="Left" VerticalAlignment="Top"/>
    </Grid>
</local:BaseDlg>


I have created a grid in BaseDlg the Box.xaml change style but when I create a button in Box.xaml the Box.xaml has not changed.

The Box.xaml just content Textblock from BaseDlg

Any help is greatly appreciated.

Thanks.
Posted
Updated 11-Mar-11 5:09am
v3

1 solution

In your template you need to add a ContentPresenter. This is where all of the controls will go.

XML
<ContentPresenter x:Name="windowContent" Content="{TemplateBinding Property=ContentControl.Content}" Margin="4"/>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900