当前位置: 首页 > news >正文

网站 手机版 电脑版 怎么做商丘网站建设公司

网站 手机版 电脑版 怎么做,商丘网站建设公司,模板王字库官方下载,模板建网站哪个品牌好工业控制中,经常会需要把一个bool 型输入信号的状态显示在面板上,使用wpf 绑定的办法,可简洁实现: 实现步骤: 1,定义类: using System; using System.Collections.Generic; using System.Com…

工业控制中,经常会需要把一个bool  型输入信号的状态显示在面板上,使用wpf 绑定的办法,可简洁实现:

实现步骤:

1,定义类:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;namespace WpfAppBoolBinding
{public class MainViewModel : INotifyPropertyChanged{private bool _myProperty;public bool MyProperty{get { return _myProperty; }set{if (_myProperty != value){_myProperty = value;OnPropertyChanged();}}}public event PropertyChangedEventHandler PropertyChanged;protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = ""){if (this.PropertyChanged != null){this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));}}}public class TestViewModel{public MainViewModel MainView { get; set; }public int couter { get; set; }}
}

2,定义bool  类型转换器:

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;namespace WpfAppBoolBinding
{[ValueConversion(typeof(bool), typeof(Brush))]public class BooleanToBrushConverter : IValueConverter{public object Convert(object value, Type targetType, object parameter, CultureInfo culture){return (bool)value ? Brushes.Green : Brushes.Red;}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){throw new NotImplementedException();}}}

3,xml 实现:

<Window x:Class="WpfAppBoolBinding.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:WpfAppBoolBinding" mc:Ignorable="d"Title="MainWindow" Height="450" Width="800"><Window.Resources><local:BooleanToBrushConverter x:Key="BooleanToBrushConverter"/></Window.Resources><Grid><StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"><Ellipse Width="50" Height="50" Fill="{Binding MainView.MyProperty, Converter={StaticResource BooleanToBrushConverter}}" Margin="10,30"/><Button Content="变换颜色" Width="60" Height="30" Click="Button_Click" Margin="10,30"/></StackPanel></Grid>
</Window>

4,进行Datacontex 绑定:

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 WpfAppBoolBinding
{/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{TestViewModel testViewModel = new TestViewModel();public MainWindow(){InitializeComponent();testViewModel.MainView = new MainViewModel();DataContext = testViewModel;}private void Button_Click(object sender, RoutedEventArgs e){testViewModel.MainView.MyProperty = !testViewModel.MainView.MyProperty;}}
}

http://www.dinnco.com/news/5723.html

相关文章:

  • 阿里巴巴怎么做公司网站刷网站关键词工具
  • 石家庄制作网站公司有哪些2345浏览器下载
  • 汕头教育的网站建设江西seo推广软件
  • 杭州建设网杭州造价平台如何做谷歌seo推广
  • 广州涉疫重点场所有更新南京百度seo代理
  • 做网站备案的公司广州seo招聘信息
  • 加强档案网站建设小程序开发工具
  • 做守望先锋h的网站怎样留别人电话在广告上
  • 做职业资格考试的网站有哪些引擎搜索技巧
  • 网站建设市场需求大南宁seo优势
  • 网站资料如何做参考文献百度推广客户端教程
  • 万网域名绑定到其它网站企业培训课程设置
  • 怎样自己做企业网站信息流广告投放平台
  • 合肥有没有做网站的单位关于软文营销的案例
  • 做海报的素材那个网站比较好百度免费发布信息
  • 沧州网站建设哪家好汕头seo
  • 哪些网站做微课赚钱免费推广软件工具
  • 企业网站网页打开慢友情链接的检查方法
  • wordpress 显示视频孝感seo
  • 东莞虎门高铁站成都网站搜索排名优化公司
  • h5个人网站模板源码云南seo简单整站优化
  • 怎么进成品网站后台陕西网站推广公司
  • 做网站推广方法有哪些巩义网站优化公司
  • 哪些网站是用h5做的销售课程培训视频教程
  • 营销型网站主机seo优化排名教程百度技术
  • 我们高清在线观看免费韩剧搜索引擎优化的具体操作
  • 做网站体会淘宝搜索关键词查询工具
  • 做视频给网站到流量免费自建网站有哪些
  • 天津网站优化步骤sem广告投放是做什么的
  • 阿甘网站建设营销推广案例