zoukankan      html  css  js  c++  java
  • WPF Window异形窗口演示

    我们先通过简单的效果展示,切换展示不同图片:

    我们先定义图片资源文件,我们可以在window资源中定义,下面的在app.xaml文件来定义:

    <Application x:Class="WPF异形窗口演示.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 StartupUri="MainWindow.xaml">
        <Application.Resources>
            <ImageBrush  ImageSource="1.jpg"  x:Key="key1"></ImageBrush>
            <ImageBrush  ImageSource="2.jpg"  x:Key="key2"></ImageBrush>
        </Application.Resources>
    </Application>

    然后通过Combox控件来进行资源样式切换

    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.Navigation;
    using System.Windows.Shapes;
    
    namespace WPF异形窗口演示
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                this.comboBox1.Items.Add("样式1");
                this.comboBox1.Items.Add("样式2");
                this.comboBox1.Items.Add("样式3");
                this.comboBox1.SelectedIndex = 0;
            }
            private void Grid_MouseMove(object sender, MouseEventArgs e)
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    this.DragMove();
    
                    //   this.Margin = new Thickness(10,10,10,10);
                }
            }
    
    
            private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                if (this.comboBox1.SelectedValue.ToString() == "样式1")
                {
                    //通过uri指向图片位置
                    this.Background = new ImageBrush(new System.Windows.Media.Imaging.BitmapImage(new Uri("3.jpg", UriKind.Relative))); ;
                }
                else if (this.comboBox1.SelectedValue.ToString() == "样式2")
                {
                    //通过资源文件获取
                    this.Background = (ImageBrush)Application.Current.Resources["key1"];
                 
                }
                else if (this.comboBox1.SelectedValue.ToString() == "样式3")
                {
                    this.Background = (ImageBrush)Application.Current.Resources["key2"];
                       
                }
            }
        }
    }

    我们可以通过这样的方式来动态实现不同效果展示
    示例小demo:

  • 相关阅读:
    JDK中Unsafe类详解
    JAVA并发理论与实践
    关于FastJSON
    指数退避算法
    MySQL多表关联查询效率高点还是多次单表查询效率高,为什么?
    App开放接口api安全性—Token签名sign的设计与实现
    使用Jmeter进行http接口性能测试
    短信验证登录实现流程
    使用 Postman 取得 Token 打另一隻 API
    SpringMVC拦截器HandlerInterceptor使用
  • 原文地址:https://www.cnblogs.com/BABLOVE/p/3234084.html
Copyright © 2011-2022 走看看