zoukankan      html  css  js  c++  java
  • wp7 控制控件显隐

    xaml:  

    xmlns:Converters="clr-namespace:TestControl"

        <phone:PhoneApplicationPage.Resources>

            <Converters:BooleanToVisibilityConverter x:Key="BoolToVisConverter" />
        </phone:PhoneApplicationPage.Resources>

                <Image Source="/TestControl;component/images/image_gifmark.png" Width="30" Height="20" Visibility="{Binding SEX, Converter={StaticResource BoolToVisConverter}}" Margin="46,434,380,55" />
                <Button Content="Vis" Height="72" HorizontalAlignment="Left" Margin="82,422,0,0" Name="button3" VerticalAlignment="Top" Width="160" Click="button3_Click"/>
                <Button Content="Col" Height="72" HorizontalAlignment="Left" Margin="258,420,0,0" Name="button4" VerticalAlignment="Top" Width="160" Click="button4_Click"/>

    cs:

    namespace TestControl
    {
        public class BooleanToVisibilityConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                var boolValue = System.Convert.ToBoolean(value);

                if (parameter != null)
                    boolValue = !boolValue;

                return boolValue ? Visibility.Visible : Visibility.Collapsed;
            }

            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return value.Equals(Visibility.Visible);
            }
        }
    }

        public class model : INotifyPropertyChanged
        {
            private bool _sex { get; set; }
            public bool SEX
            {
                get
                {
                    return _sex;
                }
                set
                {
                    _sex = value;
                    RaisePropertyChanged("SEX");
                }
            }

            public event PropertyChangedEventHandler PropertyChanged;
            public void RaisePropertyChanged(string propertyname)
            {
                if (PropertyChanged != null)
                {
                    this.PropertyChanged(this, new PropertyChangedEventArgs(propertyname));

                }

            }
        }

            model mymodel = new model() { SEX = false };

            this.DataContext = mymodel;

            private void button3_Click(object sender, RoutedEventArgs e)
            {
                mymodel.SEX = true;
            }

            private void button4_Click(object sender, RoutedEventArgs e)
            {
                mymodel.SEX = false;
            }

  • 相关阅读:
    TP中模型实例化
    PHP中面向对象编程思想的3个特征
    static关键字的新用法
    PHP中与类有关的运算符
    PHP中与类和对象有关的几个系统函数
    PHP中与类有关的几个魔术常量
    PHP与类有关的几个魔术方法
    PHP中类型约束
    PHP对象类型转换
    ubuntu MySQL拒绝远程连接(10061)
  • 原文地址:https://www.cnblogs.com/androllen/p/2922004.html
Copyright © 2011-2022 走看看