码迷,mamicode.com
首页 > Windows程序 > 详细

WPF设置窗口模式(Windowstyle=“None”)

时间:2016-10-29 01:41:08      阅读:392      评论:0      收藏:0      [点我收藏+]

标签:xmlns   交互   code   demo   conf   nbsp   http   eric   pre   

当WindowStyle=“None”时,设置AllowsTransparency="True",则不会出现黑色Border,然后可以另外设置外边的Border和BorderThickness;

当WindowStyle=“None”时,生成的窗体无法移动,此时需要定义MouseMove="Window_MouseMove"事件,实现鼠标左键按下可拖动窗口;

xaml代码如下:

<Window x:Class="CustomWindowDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:CustomWindowDemo"
        mc:Ignorable="d" MouseMove="Window_MouseMove"
        WindowStyle="None" AllowsTransparency="True" BorderBrush="Orange" BorderThickness="3,0,3,3"
        Title="MainWindow" Height="300" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="80"></RowDefinition>
        </Grid.RowDefinitions>
        <StackPanel Grid.Row="0" Background="Orange">
            <TextBlock Margin="20,5,5,5" Foreground="Red" Text="TestWindow" FontSize="14" VerticalAlignment="Center"/>
        </StackPanel>
        <TextBlock Margin="20,30" FontSize="16" Text="This is a Test Window of customized." Grid.Row="1" TextAlignment="Center" VerticalAlignment="Center"></TextBlock>
        <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
            <Button Name="Cancel" Click="Cancel_Click" Margin="0,5,20,5" Height="40" Width="60">Cancel</Button>
            <Button Name="Confirm" Click="Confirm_Click" Margin="20,5,0,5" Height="40" Width="60">Confirm</Button>
        </StackPanel>
    </Grid>
</Window>

后台代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 CustomWindowDemo
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Window_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
                //Window.DragMove();
            }
        }
    }
}

 

WPF设置窗口模式(Windowstyle=“None”)

标签:xmlns   交互   code   demo   conf   nbsp   http   eric   pre   

原文地址:http://www.cnblogs.com/runningRain/p/6009688.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!