mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect.git
synced 2025-06-25 05:54:14 +08:00
29 lines
931 B
C#
29 lines
931 B
C#
using System;
|
|
using System.Globalization;
|
|
using Avalonia.Data;
|
|
using Avalonia.Data.Converters;
|
|
|
|
namespace detect.gui.Converters;
|
|
|
|
public class IndexToBoolConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
// 传入的参数是Index
|
|
if (value is int selectedIndex && parameter is string indexString && int.TryParse(indexString, out int index))
|
|
{
|
|
return selectedIndex == index;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
// 仅当选中某个 RadioButton 时更新下标
|
|
if (value is bool isChecked && isChecked && parameter is string indexString && int.TryParse(indexString, out int index))
|
|
{
|
|
return index;
|
|
}
|
|
return BindingOperations.DoNothing;
|
|
}
|
|
} |