Hi Jenny,
try this tested code:
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace WpfApp2.general_pages
{
class Pages_ViewModel : ICommand, INotifyPropertyChanged
{
public Color Tb3BackgroundColor { get; set; } = Colors.Orange;
public Visibility Tb1Visibility { get; set; } = Visibility.Hidden;
public Visibility Tb2Visibility { get; set; } = Visibility.Hidden;
public Visibility Tb3Visibility { get; set; } = Visibility.Hidden;
public bool Tb3BeginStoryBoard { get; set; } = false;
private void SetVisibility(bool? tb1, bool? tb2, bool? tb3)
{
if (tb1.HasValue)
{
this.Tb1Visibility = (tb1.Value) ? Visibility.Visible : Visibility.Hidden;
OnPropertyChanged(nameof(Tb1Visibility));
}
if (tb2.HasValue)
{
this.Tb2Visibility = (tb2.Value) ? Visibility.Visible : Visibility.Hidden;
OnPropertyChanged(nameof(Tb2Visibility));
}
if (tb3.HasValue)
{
this.Tb3Visibility = (tb3.Value) ? Visibility.Visible : Visibility.Hidden;
OnPropertyChanged(nameof(Tb3Visibility));
}
}
public void Execute(object parameter)
{
switch (parameter.ToString())
{
case "General":
SetVisibility(true, null, null);
break;
case "Primary":
SetVisibility(null, true, true);
break;
case "Secondary":
Tb3BeginStoryBoard = true;
OnPropertyChanged(nameof(Tb3BeginStoryBoard));
break;
default:
break;
}
}
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter) => true;
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propName = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
}