如何制作基础窗口类 [英] How to make a Base Window class

查看:60
本文介绍了如何制作基础窗口类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有WPF表格.我需要将其作为基础窗口类.我的WPF表单具有UI控件,该控件是XAML代码,就像任何WPF表单一样.如何将XAML绑定到我的基类.我尝试使用"ResourceDictionary"作为一个tempalte 基本窗口类.当我将UI放入资源字典中时,我发现无法打开并在设计模式下查看我的UI.谁能帮我这个忙.

I have a WPF form . I need to make it as a Base Window class. My WPF form having UI controls which is in XAML code as in any WPF form. How can I bind that XAML to my base class. I tried to use "ResourceDictionary" as a tempalte for the base window class. When I put my UI into a resource dictionary I found no way to open and see my UI in the design mode. Can anyone help me on this.

推荐答案

如果要创建具有自定义外观的自定义窗口,请参阅我的博客文章: http://blog.magnusmontin.net/2013/03/16/how-to-create-a-custom-window-in-wpf/

If you want to create a custom window with a custom look, please refer to my blog post: http://blog.magnusmontin.net/2013/03/16/how-to-create-a-custom-window-in-wpf/

如果您想定义一个基类,以添加一些继承自该类的所有窗口通用的属性和/或方法,则只需创建一个从内置Window类继承并继承的类即可.制作所有窗口实例 从此继承而不是内置的继承:

If you want to define a base class that adds some properties and/or methods that are common for all windows that inherit from this class, it is just a matter of creating a class that inherits from the built-in Window class and make all of your window instances inherit from this one instead of the built-in one:

    public class MyWindow : System.Windows.Window
    {
        //add your methods, properties, .etc.
    }

Window1.xaml.cs:

public partial class Window1 : MyWindow
    {
        public Window1()
        {
            InitializeComponent();
        }
    }


Window1.xaml:

<local:MyWindow x:Class="WpfApplicationCanvas.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplicationCanvas"
        Title="Window1" Height="300" Width="300">
    <Grid>
        
    </Grid>
</local:MyWindow>

如果只想向窗口实例添加一些内置控件,则可以定义一个或多个包含这些控件的UserControl并将UserControl实例添加到窗口: http://www.codeproject.com/Articles/32825/How-to-Creating-a-WPF-User-Control-using-it-in-a-W

If you just want to be able add some built-in controls to an instance of a window, you could define one or more UserControls that contains these controls and add instances of the UserControls to the window: http://www.codeproject.com/Articles/32825/How-to-Creating-a-WPF-User-Control-using-it-in-a-W

CustomControl和UserControl之间的区别: http://wpftutorial.net/CustomVsUserControl.html

The differences between CustomControls and UserControls: http://wpftutorial.net/CustomVsUserControl.html

您还应该研究样式和模板: http://msdn.microsoft.com/zh-cn/library/ms745683(v=vs.110).aspx

You should also look into styles and templates: http://msdn.microsoft.com/en-us/library/ms745683(v=vs.110).aspx


这篇关于如何制作基础窗口类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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