4

我将一个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.

4

1 回答 1

2

您可能必须Reporting先将参数转换为枚举类型:

int val = System.Convert.ToInt32((Reporting)parameter);
bool visibility = OperationList.Exists(list => list.Id == val);
于 2013-04-07T16:39:56.647 回答