我将一个Enum
具有基础值 ( int
) 作为参数从一个传递XAML
到一个IValueConverter
。这个想法是使用该Enum
值对列表进行迭代以检查该值是否存在并返回 a Visibility
enum
。该列表的类型为int
。但是当将 传递Enum
给 时converter
,我不能将Enum
后面传递给int
。通过“快速观察”查看参数,我根本看不到基础价值或任何价值。
枚举例如
public class Operations
{
public enum Reporting
{
ReportAccounts = 101,
ReportEngineering = 102,
ReportSoftware = 103,
ReportPR = 104,
ReportCRM = 105
}
public enum Editing
{
EditUser = 201,
EditAccess = 202,
EditView = 203
}
}
XAML 例如
Visibility={Binding Converter={StaticResource VisibilityConverter},
ConverterParameter={x:Static Operations:Reporting.ReportAccounts}}
IValueConverter
例如
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
bool visibility = OperationList.Exists(list => list.Id == (int)parameter);
if (visibility == true)
{
return Visibility.Visible;
}
else
{
return Visibility.Collapsed;
}
}
我想知道当枚举传递给IValueConverter
.