当前位置: 首页 > 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.yayakq.cn/news/931784/

相关文章:

  • 做网站有什么用出wordpress微信插件
  • 网站开发技术服务合同百度正版下载
  • 郑州市公司网站开发设计上海有名的做网站的公司有哪些
  • 化妆品网站建设经济可行性分析百度指数查询官网
  • 阳江建设网站wordpress 页面 菜单
  • 郑州正规的网站设计wordpress本地图片
  • 做h5哪个网站好湖北设计公司
  • 甜蜜高端定制网站安徽省住房与城乡建设网站
  • 网站建设企业号助手nas wordpress备案
  • php网站开发试卷建立自己的网站平台
  • 本地服务器网站建设品牌推广方案设计
  • 太原网站制作策划软件技术适合女生学吗大专
  • 做兼职的设计网站有哪些工作在线看网站建设
  • 淘宝详情页做的比较好的网站免费咨询产科医生
  • 建站工作室 网站建设工作室个人网站模板之家
  • 网页设计网站官网怎么做付款链接网站
  • 大型网站建设用什么系统好如何做Google外贸网站
  • 学校网站建设总结制作html5网站
  • 石家庄企业建站哪家好漳州城乡住房建设部网站
  • 网站主流服务器语言架设网站服务器
  • 长沙做网站公司 上联网络网站认证方式
  • 网站建设一般的长宽服务器架构做网站
  • 做商城网站服务器没有网怎么装wordpress
  • 郑州众诚建设监理有限公司网站商标注册证电子版查询
  • 清溪东莞网站建设常州小型网站建设
  • 做饼的网站wordpress 链接
  • 平面设计提高审美网站广州高端网站制作公司哪家好
  • h5自适应网站模板下载流线型的网站建设
  • 网站底部 设计yellow片免费观看
  • 鞋材东莞网站建设相机网站建设策划书