Files
serein-flow/Workbench/Converters/CountToVisibilityConverter.cs
fengjiayi 152077e9b5 1. 重新设计了Generate项目及相关特性的命名,避免与其他类型混淆。
2. 补充了部分注释。
3. 修改了删除容器节点时,容器内子节点未正确删除的问题。
2025-07-30 21:15:07 +08:00

34 lines
1.0 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows;
namespace Serein.Workbench.Converters
{
internal class CountToVisibilityConverter : IValueConverter
{
public bool Inverse { get; set; } = false; // 可选:反转逻辑
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is IEnumerable collection)
{
int count = 0;
foreach (var item in collection) count++;
bool visible = count > 0;
if (Inverse) visible = !visible;
return visible ? Visibility.Visible : Visibility.Collapsed;
}
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
}
}