Files
aistudio-wpf-diagram/AIStudio.Wpf.DiagramDesigner/Controls/MyTabControl.cs
2023-04-15 21:55:27 +08:00

46 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace AIStudio.Wpf.DiagramDesigner.Controls
{
public class DiagramTabControl : TabControl
{
public DiagramTabControl()
{
// Attach event handler to TabControl.SelectionChanged event
this.SelectionChanged += DiagramTabControl_SelectionChanged;
this.IsVisibleChanged += DiagramTabControl_IsVisibleChanged;
}
private void DiagramTabControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
foreach (var item in this.Items)
{
if (item is DiagramViewModel viewModel)
{
viewModel.ShowSearch = false;
}
}
}
private void DiagramTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Iterate through all TabItems and manually set the Visibility property
foreach (var item in this.Items)
{
if (item is DiagramViewModel viewModel)
{
if (item != this.SelectedItem)
{
viewModel.ShowSearch = false;
}
}
}
}
}
}