mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-17 13:26:34 +08:00
重构中day1,写了很多,不知道怎么说清楚
This commit is contained in:
33
Workbench/Converters/CountToVisibilityConverter.cs
Normal file
33
Workbench/Converters/CountToVisibilityConverter.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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
|
||||
{
|
||||
public 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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user