zoukankan      html  css  js  c++  java
  • 自定义类似迅雷的漂浮窗口

    1. 自定义窗口样式,通过自定义ControlTemplate改变窗口的形状.
      <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">     
      
          <!--窗口模板-->
          <ControlTemplate x:Key="BaseWindowControlTemplate" TargetType="{x:Type Window}">
              <Grid Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">       
                  <Ellipse Stroke="YellowGreen" StrokeThickness="3">           
                          <Ellipse.Fill>                    
                              <VisualBrush >
                                  <VisualBrush.Visual>                         
                                      <Image  Source=".Resourcemessage.jpg"/>                                                         
                              </VisualBrush.Visual>
                              </VisualBrush>                   
                      </Ellipse.Fill>               
                  </Ellipse>           
              </Grid>
          </ControlTemplate>
      
          <!--窗口样式-->
          <Style x:Key="BaseWindowStyle" TargetType="{x:Type Window}">
              <Setter Property="Template" Value="{StaticResource BaseWindowControlTemplate}"/>
              <Setter Property="Background" Value="Transparent" />
              <Setter Property="WindowStyle" Value="None" />
              <Setter Property="AllowsTransparency" Value="True" />        
          </Style>
      
      </ResourceDictionary>
    2. 主窗口的xaml文件
      <Window x:Class="FlowNotes.MainWindow"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              Title="MainWindow" Height="50" Width="50" MouseLeftButtonDown="Window_MouseLeftButtonDown" WindowStyle="None" WindowStartupLocation="Manual" ResizeMode="NoResize" SizeToContent="Manual" BorderThickness="0" MouseDoubleClick="Window_MouseDoubleClick" IsTabStop="False" ShowInTaskbar="False">
          <Window.Resources>
              <ResourceDictionary>
                  <ResourceDictionary.MergedDictionaries>
                      <ResourceDictionary Source="Generic.xaml"/>
                  </ResourceDictionary.MergedDictionaries>         
              </ResourceDictionary>    
          </Window.Resources>
          <Window.Style>
              <Style TargetType="{x:Type Window}"  BasedOn="{StaticResource BaseWindowStyle}" />
          </Window.Style>
      </Window>
    3. 主窗口代码:
      /// <summary>
          /// Interaction logic for MainWindow.xaml
          /// </summary>
          public partial class MainWindow : Window
          {  
              public MainWindow()
              {         
                  InitializeComponent();
                  SetWindowLocation();
                  
              }
      
              //无标题栏窗口的移动
              private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
              {
                  this.DragMove();
              }
              //设置窗口距离右上角100单位
              private void SetWindowLocation()
              {
                  double screenHeight = SystemParameters.FullPrimaryScreenHeight;
                  double screenWidth = SystemParameters.FullPrimaryScreenWidth;
                  this.Left = screenWidth - 100;
                  this.Top = 100;
              }
                             
          }
    4. 运行结果:
      image
  • 相关阅读:
    设计模式之工厂模式-抽象工厂(02)
    1036 跟奥巴马一起编程 (15 分)
    1034 有理数四则运算 (20 分)
    1033 旧键盘打字 (20 分)
    1031 查验身份证 (15 分)
    大学排名定向爬虫
    1030 完美数列 (25 分)二分
    1029 旧键盘 (20 分)
    1028 人口普查 (20 分)
    1026 程序运行时间 (15 分)四舍五入
  • 原文地址:https://www.cnblogs.com/phenixyu/p/4210873.html
Copyright © 2011-2022 走看看