• WPF(MultiBinding 数据对比验证,启用提交)


    <Window x:Class="TestOfMultiBinding.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <StackPanel Background="LightBlue" >
            <TextBox x:Name="textBox1" Height="23" Margin="5" />
            <TextBox x:Name="textBox2" Height="23" Margin="5,0" />
            <TextBox x:Name="textBox3" Height="23" Margin="5" />
            <TextBox x:Name="textBox4" Height="23" Margin="5,0" />
            <Button x:Name="button1" Content="Submit" 
                    Width="80" Margin="5" />
        </StackPanel>
    </Window>
    
    using System;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    
    namespace TestOfMultiBinding
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent(); 
                this.SetMultiBinding();
            }
    
            private void SetMultiBinding()
            {
                Binding b1 = new Binding("Text")
                                 {
                                     Source = this.textBox1
                                 };
    
                Binding b2 = new Binding("Text")
                                 {
                                     Source = this.textBox2
                                 };
    
                Binding b3 = new Binding("Text")
                                 {
                                     Source = this.textBox3
                                 };
    
                Binding b4 = new Binding("Text")
                                 {
                                     Source = this.textBox4
                                 };
    
    
                MultiBinding mb = new MultiBinding()
                                      {
                                          Mode = BindingMode.OneWay
                                      };
                mb.Bindings.Add(b1);
                mb.Bindings.Add(b2);
                mb.Bindings.Add(b3);
                mb.Bindings.Add(b4);
    
                mb.Converter = new LogonMultiBindingConverter();
    
                this.button1.SetBinding(Button.IsEnabledProperty, mb);
            }  
        }
    
        public class LogonMultiBindingConverter : IMultiValueConverter
        {
            public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (!values.Cast<string>().Any(text => string.IsNullOrEmpty(text))
                    && values[0].ToString() == values[1].ToString()
                    && values[2].ToString() == values[3].ToString())
                {
                    return true;
                }
    
                return false;
            }
    
            //不会被调用
            public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }
    }
    


  • 相关阅读:
    alibaba/fescar 阿里巴巴 开源 分布式事务中间件
    InnoDB表优化
    解密日志文件工具类
    MYSQL 数据库结构优化
    MYSQL 索引优化
    MYSQL 表转 JavaBean 工具类
    MYSQL 优化
    mysql 数据库备份和恢复
    DMA-Direct Memory Access
    mysql 优化之 doublewrite buffer 机制
  • 原文地址:https://www.cnblogs.com/wjchang/p/3671535.html
Copyright © 2020-2023  润新知