none
what problem with my code RRS feed

  • 问题

  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Controls;
    using System.Windows;
    using System.Windows.Media.Imaging;

    namespace SellApp.Views.Control
    {
        class ComboBoxValidator:Image
        {
            public ComboBoxValidator()
            {
                this.Visibility = Visibility.Hidden;
                VerifyControl.SelectionChanged+=new SelectionChangedEventHandler(VerifyControl_SelectionChanged);
            }
            private void VerifyControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                Check();
            }
            public bool Check()
            {
                if (VerifyControl.SelectedIndex == 0)
                {
                    BitmapImage myBitmapImage = new BitmapImage();
                    myBitmapImage.BeginInit();
                    myBitmapImage.UriSource = new Uri("Resources/check_error.gif", UriKind.Relative);
                    myBitmapImage.EndInit();
                    this.Source = myBitmapImage;

                    this.Visibility = Visibility.Visible;
                    return false;
                }
                else
                {
                    BitmapImage myBitmapImage = new BitmapImage();
                    myBitmapImage.BeginInit();
                    myBitmapImage.UriSource = new Uri("Resources/access_allowu.gif", UriKind.Relative);
                    myBitmapImage.EndInit();
                    this.Source = myBitmapImage;

                    this.Visibility = Visibility.Visible;
                    return true;
                }
               
            }
            #region  VerifyControl
            /// <summary>
            /// 检查是否允许为空
            /// </summary>
            public static DependencyProperty VerifyControlProperty =
                    DependencyProperty.Register(
                            "VerifyControl",
                            typeof(ComboBox),
                            typeof(ComboBoxValidator),
                            new FrameworkPropertyMetadata(null));
            /// <summary>
            /// 是否允许为空
            /// </summary>

            public ComboBox VerifyControl
            {
                get { return (ComboBox)GetValue(VerifyControlProperty); }
                set
                {
                    SetValue(VerifyControlProperty, value);
                }
            }
            #endregion
        }
    }

    2012年6月15日 13:27

答案