Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.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
直接从数据库WPF C#MVVM绑定ItemsSources列表框_C#_Wpf_Mvvm_Listbox_Itemssource - Fatal编程技术网

直接从数据库WPF C#MVVM绑定ItemsSources列表框

直接从数据库WPF C#MVVM绑定ItemsSources列表框,c#,wpf,mvvm,listbox,itemssource,C#,Wpf,Mvvm,Listbox,Itemssource,我已经为ViewModel的属性绑定了ItemsSource列表框,该属性是一个ObservableCollection,我喜欢显示表USRROL中的角色列表,这是我的XAML: <ListBox Name="ListRoles" Background="White" ItemsSource="{Binding ListeRole, IsAsync=True}" DisplayMemberPath=

我已经为ViewModel的属性绑定了ItemsSource列表框,该属性是一个ObservableCollection,我喜欢显示表USRROL中的角色列表,这是我的XAML:

<ListBox Name="ListRoles" 
         Background="White" 
         ItemsSource="{Binding ListeRole, IsAsync=True}"                 
         DisplayMemberPath=role
         BorderBrush="white" Width="120" 
         FontSize="11"    
         ScrollViewer.HorizontalScrollBarVisibility="Disabled">

请注意,此代码不起作用,有人能告诉我错误吗?

您在输出窗口中是否收到任何错误消息?DataContext是否设置为您的ConstructureViewModel?在构造函数中填写您的
\u ListRole
,或者在填写
\u ListRole
后调用
RaisePropertyChanged(“ListRole”)在后面显示您的代码。您是否将数据上下文设置为VM实例?在输出窗口中是否收到任何错误消息?DataContext是否设置为您的ConstructureViewModel?在构造函数中填写您的
\u ListRole
,或者在填写
\u ListRole
后调用
RaisePropertyChanged(“ListRole”)在后面显示您的代码。您是否将数据上下文设置为VM实例?
ObservableCollection<String> _listeRole = new ObservableCollection<String>            ();
public ObservableCollection<String> ListeRole
{
    get { return _listeRole ; }
    set { _listeRole = value; RaisePropertyChanged("ListeRole"); }
}
public CollectionViewSource CvsListeRole = new CollectionViewSource();
ConstructeurviewModel() { _listeRole = new ObservableCollection<String>();
    CvsListeRole.Source = _listeRole ;
    FiltresStatutActifsView = CvsFiltresStatut.View;
}
  public string role {get;set;}