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

  • 相关阅读:
    FJNU 1151 Fat Brother And Geometry(胖哥与几何)
    FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术)
    FJNU 1159 Fat Brother’s new way(胖哥的新姿势)
    HDU 3549 Flow Problem(最大流)
    HDU 1005 Number Sequence(数列)
    Tickets(基础DP)
    免费馅饼(基础DP)
    Super Jumping! Jumping! Jumping!(基础DP)
    Ignatius and the Princess IV(基础DP)
    Keywords Search(AC自动机)
  • 原文地址:https://www.cnblogs.com/androllen/p/2922004.html
Copyright © 2011-2022 走看看