Hi,
try this demo:
XAML:
<Window x:Class="WpfApp1.Window034"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp034"
mc:Ignorable="d"
Title="Window034" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<TabControl>
<TabItem Header="Tab1">
<Button Content="Change Visbility of Tab2" Command="{Binding}" Width="200" Height="50"/>
</TabItem>
<TabItem Header="Tab2" Visibility="{Binding Vis}"/>
<TabItem Header="Tab3"/>
</TabControl>
</Window>
and ViewModel:
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
namespace WpfApp034
{
public class ViewModel : ICommand, INotifyPropertyChanged
{
public Visibility Vis { get; set; }
public event EventHandler? CanExecuteChanged;
public event PropertyChangedEventHandler? PropertyChanged;
public bool CanExecute(object? parameter) => true;
public void Execute(object? parameter)
{
this.Vis = (this.Vis == Visibility.Visible) ? Visibility.Collapsed : Visibility.Visible;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Vis)));
}
}
}
Result: