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:

  • 相关阅读:
    将网站从WSS2.0升级到WSS3.0的心得
    Teched 2008课程:ADO.NET Data Service & UC开发概览
    我的基于Silverlight2的相册,也刚刚升级到了RTW了。
    ubuntu16.04设置python3为默认及一些库的安装
    CDMA手机的MEID
    CDMA Subscription 模式设置
    Android架构纵横谈之——软件自愈能力(转载)
    CDMA系统中的用户识别卡(UIM)和空中激活技术(OTA)
    手机信号强度全解析
    GSMPhone与CDMAPhone切换过程
  • 原文地址:https://www.cnblogs.com/BABLOVE/p/3234084.html
Copyright © 2011-2022 走看看