WPF:如何使用Custorm控件 [英] WPF: How To Use Custorm Controls

查看:63
本文介绍了WPF:如何使用Custorm控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我创建了一个名为Base_Dialog的自定义控件库,并内置了Base_Dialog --- BaseDlg
像这样:

Hello,

I have created a custom control Library called Base_Dialog and I built in Base_Dialog ---BaseDlg
like this:

<pre lang="cs">using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows;<br />
using System.Windows.Controls;<br />
using System.Windows.Data;<br />
using System.Windows.Documents;<br />
using System.Windows.Input;<br />
using System.Windows.Media;<br />
using System.Windows.Media.Imaging;<br />
using System.Windows.Navigation;<br />
using System.Windows.Shapes;<br />
namespace Base_Dialog<br />
{<br />
    public class BaseDlg : Window<br />
    {<br />
        static BaseDlg()<br />
        {<br />
            DefaultStyleKeyProperty.OverrideMetadata(typeof(BaseDlg), new FrameworkPropertyMetadata(typeof(BaseDlg)));<br />
        }<br />
    }<br />
}</pre>




并且在Generic.xaml




and in Generic.xaml

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



我在AssemblyInfo.cs文件中编写了以下代码:



and I wrote the following code in the AssemblyInfo.cs file:

<br />
[assembly: XmlnsDefinition("http://schemas.sheva.com/winfx/2006/xaml/presentation", "Base_Dialog")]


然后打开wpf应用程序名称((wpf))并添加引用项目((Base_Dialog))

xaml代码是:


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

xaml code is:

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



我已经在BaseDlgBox.xaml更改样式中创建了一个网格,但是当我在Box.xaml中创建按钮时,Box.xaml却没有更改.

Box.xaml仅来自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.

推荐答案

在模板中,您需要添加ContentPresenter.这是所有控件的去向.

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

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


这篇关于WPF:如何使用Custorm控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆