• 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;
            }

  • 相关阅读:
    jar 反编译工具
    SpringBoot 中注解方式的拦截过滤
    jetty 启动项目在pom.xml 的配置
    java Exception 处理汇总
    mysql-覆盖索引
    程序员为何如此累
    启动centos 不带桌面
    Linux 和 Vim 常用命令整理
    How to Use tomcat on Linux
    Mac Book 问题汇集
  • 原文地址:https://www.cnblogs.com/androllen/p/2922004.html
Copyright © 2020-2023  润新知