zoukankan      html  css  js  c++  java
  • WPF自定义窗口基类

    WPF自定义窗口基类时,窗口基类只定义.cs文件,xaml文件不定义。继承自定义窗口的类xaml文件的根节点就不再是<Window>,
    而是自定义窗口类名(若自定义窗口与继承者不在同一个命名空间,还得加上命名空间),继承自定义窗口类后台代码也得修改为继承自自定义窗口
    exp:

    //继承Window类的自定义窗口类
    namespace WPF_Study.Entity
    {
       using System.Windows;
    
       public class WindowBase:Window
        {
            private const int Fixed_Width = 540;
            private const int Fixed_Height = 350;
    
            public WindowBase() : base()
            {
                this.MaxWidth = Fixed_Width;
                this.MaxHeight = Fixed_Height;
                this.MinWidth = Fixed_Width;
                this.MinHeight = Fixed_Height;
            }
        }
    }
    
    //继承自定义窗口 
    //xaml文件
    <localEntity:WindowBase x:Class="WPF_Study.TestWindowBase"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:localEntity="clr-namespace:WPF_Study.Entity"
            Title="TestWindowBase" >
        <Grid>
            <Grid.Resources>
                <Style TargetType="{x:Type Button}">
                    <Setter Property="Width" Value="60"/>
                    <Setter Property="Height" Value="30"/>
                    <Setter Property="Margin" Value="5"/>
                </Style>
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition Height="40*"/>
                <RowDefinition Height="221*"/>
            </Grid.RowDefinitions>
            <WrapPanel Grid.Row="0" Grid.Column="0">
                <Button Content="查询" x:Name="btnSearch"></Button>
                <Button Content="新增" x:Name="btnAdd"></Button>
                <Button Content="修改" x:Name="btnAmend"></Button>
                <Button Content="删除" x:Name="btnDelete"></Button>
            </WrapPanel>
            <DataGrid x:Name="dataGrid" AutoGenerateColumns="False" Grid.Row="2" Grid.Column="0" CanUserAddRows="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="窗口编号" Binding="{Binding Win}"/>
                    <DataGridTextColumn Header="评价器地址" Binding="{Binding Evalutor}"/>
                    <DataGridTextColumn Header="条屏地址" Binding="{Binding StripeScreen}"/>
                    <DataGridTextColumn Header="IP" Binding="{Binding IP}"/>
                    <DataGridTextColumn Header="注册设备号" Binding="{Binding RegNum}"/>
                    <DataGridTextColumn Header="描述" Binding="{Binding Description}" Width="*"/>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
    </localEntity:WindowBase>
    //对应后台代码
    using WPF_Study.Entity;
    
    namespace WPF_Study
    {
        /// <summary>
        /// Interaction logic for TestWindowBase.xaml
        /// </summary>
        public partial class TestWindowBase : WindowBase
        {
            public TestWindowBase()
            {
                InitializeComponent();
            }
        }
    }
    

      

  • 相关阅读:
    浅谈 cosos2d-x 的ImageView和Sprite的区别
    浅谈JS数据遍历的几种方式
    浅谈Cocos2d-js cc.director
    JavaScript的Let用法
    JS开发工具WebStorm使用快捷键
    python 文件操作
    浅谈代码自动构建工具
    rhel6.4 zabbix 安装时少的bcmath mbstring
    Security:090476]Invalid/unknown SSL header was received from peer locahost during SSL handshake
    jconsole
  • 原文地址:https://www.cnblogs.com/come-on-come-on/p/4643144.html
Copyright © 2011-2022 走看看