Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# dxe:列表框未检查项目_C#_Wpf_Listbox_Devexpress - Fatal编程技术网

C# dxe:列表框未检查项目

C# dxe:列表框未检查项目,c#,wpf,listbox,devexpress,C#,Wpf,Listbox,Devexpress,我正在创建一个列表框(devexpress控件),如下所示 <dxe:ListBoxEdit x:Name="lstBoxFeatures" DisplayMember="Description" ValueMember="FeatureId" SelectionMode="Multiple" ItemsSource="{Binding Path=DataContext.Features, RelativeSource={

我正在创建一个列表框(devexpress控件),如下所示

 <dxe:ListBoxEdit x:Name="lstBoxFeatures" DisplayMember="Description" ValueMember="FeatureId" SelectionMode="Multiple"
                                 ItemsSource="{Binding Path=DataContext.Features, RelativeSource={RelativeSource AncestorType=Window}}" Height="320"                                     
                                 EditValue="{Binding Path=DataContext.SelectedFeatures, RelativeSource={RelativeSource AncestorType=Window}}"
                                 >
                    <dxe:ListBoxEdit.StyleSettings>
                        <dxe:CheckedListBoxEditStyleSettings  />    
                    </dxe:ListBoxEdit.StyleSettings>                                                  
                </dxe:ListBoxEdit>         
获取功能列表的过程

_CustomerLicense.Features = GetFeatureList(SelectedLicense.Product.ProductId);
_CustomerLicense.SelectedFeatures =_CustomerLicense.Features.Where(x => FeaturesIds.Contains(x.FeatureId)).ToList();
   private List<Feature> GetFeatureList(Project.Common.Domain.ProductEnum ProductID )
    {
        var Res = new List<Feature>();
        var Features = new LicenseService().GetFeatures(ProductID);
        Features.ForEach((x)=> {
            Res.Add(new Feature(x));
        });
        return Res;
    } 
私有列表GetFeatureList(Project.Common.Domain.ProductEnum ProductID)
{
var Res=新列表();
var Features=new LicenseService().GetFeatures(ProductID);
功能。ForEach((x)=>{
Res.Add(新功能(x));
});
返回Res;
} 
我的看法是这样的

 public List<Feature> Features
    {
        get { return _Features;}
        set
        {
            _Features = value;
            this.NotifyPropertyChanged("Features");
        }
    }     

    public List<Feature> SelectedFeatures
    {
        get { return _SelectedFeatures; }
        set
        {
            _SelectedFeatures = value;
            NotifyPropertyChanged("SelectedFeatures");
        }
    }
公共列表功能
{
获取{return\u Features;}
设置
{
_特征=价值;
此项。NotifyPropertyChanged(“功能”);
}
}     
公共列表选定功能
{
获取{return\u SelectedFeatures;}
设置
{
_SelectedFeatures=值;
NotifyPropertyChanged(“SelectedFeatures”);
}
}
当我运行应用程序时,它会设置值,列表框中会填充列表中的所有资源,但不会选中所选功能。
关于,
SelectedFeatures
集合应包含
Features
集合中的
Feature
实例的子集。试试这个:

var features = GetFeatureList(SelectedLicense.Product.ProductId);
_CustomerLicense.Features = features;

var selectedFeatureIds = _CustomerLicense.Features.Where(x => FeaturesIds.Contains(x.FeatureId)).Select(x => x.FeatureId).ToList();
_CustomerLicense.SelectedFeatures = features.Where(x => selectedFeatureIds.Contains(x.FeatureId)).ToList();

尝试将
SelectedFeatures
声明为对象列表(您还需要更改
\u SelectedFeatures
):

公共列表所选功能
{
获取{return\u SelectedFeatures;}
设置
{
_SelectedFeatures=值;
NotifyPropertyChanged(“SelectedFeatures”);
}
}
并更改此行:

_CustomerLicense.SelectedFeatures =_CustomerLicense.Features.Where(x => FeaturesIds.Contains(x.FeatureId)).Cast<object>().ToList();
\u CustomerLicense.SelectedFeatures=\u CustomerLicense.Features.Where(x=>FeaturesIds.Contains(x.FeatureId)).Cast().ToList();

谢谢Arthur,就像你说的那样,我将选定的功能更改为对象,效果很好。非常感谢。
_CustomerLicense.SelectedFeatures =_CustomerLicense.Features.Where(x => FeaturesIds.Contains(x.FeatureId)).Cast<object>().ToList();