2025-03-17 22:17:28 +08:00

40 lines
1.2 KiB
C#

using System.Globalization;
using System.Net.Mime;
using System.Windows;
using System.Windows.Data;
using Seyounth.Hyosung.Data.Models;
using Seyounth.Hyosung.ViewModels;
namespace Seyounth.Hyosung.ViewConverter;
public class PalletToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Pallet pallet)
{
// 这里根据 Pallet 类的属性选择合适的字符串表示
return pallet.Name;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string palletName)
{
// 这里需要根据实际情况实现反向转换逻辑
// 例如,从名称查找对应的 Pallet 对象
// 假设在 ViewModel 中有一个 Pallets 集合
// 修正:获取正确的 ViewModel 引用
var viewModel = Application.Current.MainWindow.DataContext as VarietyViewModel;
if (viewModel != null)
{
return viewModel.Pallets.FirstOrDefault(p => p.Name == palletName);
}
}
return null;
}
}