Mais conteúdo relacionado
Semelhante a Uwpでみるxaml入門第二回 (7)
Mais de Makoto Nishimura (20)
Uwpでみるxaml入門第二回
- 16. INotifyPropertyChanged = 変更を通知する仕組み
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
- 19. だめなやつ・・・
public class MainPageViewModel : ViewModelBase
{
private Visibility _visibility;
public Visibility visibility
{
get { return _visibility; }
set
{
_visibility = value;
this.NotifyPropertyChanged("visibility");
}
}
- 20. IValueConverter で型をコンバート
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value,Type targetType, object parameter, string language)
{
// valueがfalseならCollapsedを返す
if (value is bool && (bool)value != false)
{
return (IsInvert) ?Visibility.Visible :Visibility.Collapsed;
}
return (IsInvert) ?Visibility.Collapsed :Visibility.Visible;
}
public object ConvertBack(object value,Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}