D23_04_具有形状内容的透明窗口(自定义窗体)

image

 

 

<Window x:Class="demo.TransparentWithShapes"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="TransparentWithShapes" Width="210" Height="170"
    
    WindowStyle="None"
    AllowsTransparency="True"
    Background="Transparent"
    >
    <Grid>

        <!--Non-Rectangular window edge, create with paths-->
        <Path Stroke="DarkGray" StrokeThickness="1" SnapsToDevicePixels="True">

            <Path.Fill>
                <LinearGradientBrush StartPoint="0.2,0" EndPoint="0.8,1" >
                    <LinearGradientBrush.GradientStops>
                        <GradientStop Color="White"  Offset="0"></GradientStop>
                        <GradientStop Color="White"  Offset="0.45"></GradientStop>
                        <GradientStop Color="LightBlue" Offset="0.9"></GradientStop>
                        <GradientStop Color="Gray" Offset="1"></GradientStop>
                    </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
            </Path.Fill>

            <Path.Data>
                <PathGeometry>
                    <PathGeometry.Figures>
                        <PathFigure StartPoint="20,0" IsClosed="True">
                            <LineSegment Point="140,0"></LineSegment>
                            <ArcSegment Point="160,20" Size="20,20" SweepDirection="Clockwise"></ArcSegment>
                            <LineSegment Point="160,60"></LineSegment>
                            <ArcSegment Point="140,80" Size="20,20" SweepDirection="Clockwise"></ArcSegment>
                            <LineSegment Point="70,80"></LineSegment>
                            <LineSegment Point="70,130"></LineSegment>
                            <LineSegment Point="40,80"></LineSegment>
                            <LineSegment Point="20,80"></LineSegment>
                            <ArcSegment Point="0,60" Size="20,20" SweepDirection="Clockwise"></ArcSegment>
                            <LineSegment Point="0,20"></LineSegment>
                            <ArcSegment Point="20,0" Size="20,20" SweepDirection="Clockwise"></ArcSegment>
                        </PathFigure>
                    </PathGeometry.Figures>
                </PathGeometry>
            </Path.Data>
            <Path.RenderTransform>
                <ScaleTransform ScaleX="1.3" ScaleY="1.3"></ScaleTransform>
            </Path.RenderTransform>
        </Path>
        <StackPanel Margin="5">
           <Button HorizontalAlignment="Right" Click="cmdClose_Click" Margin="0,5,10,0">x</Button>
            <TextBlock MouseLeftButtonDown="window_MouseLeftButtonDown" TextWrapping="Wrap"  FontSize="15" HorizontalAlignment="Center">This is a balloon-shaped window.</TextBlock>
        </StackPanel>
    </Grid>
</Window>

 

TransparentWithShapes (窗体类)

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.Shapes;

namespace demo
{
    /// <summary>
    /// TransparentWithShapes.xaml 的交互逻辑
    /// </summary>
    public partial class TransparentWithShapes : Window
    {
        public TransparentWithShapes()
        {
            InitializeComponent();
        }

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

        private void window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }
    }
}
posted @ 2014-11-02 13:55  xiepengtest  阅读(160)  评论(0编辑  收藏  举报