WPF Databinding combobox to a list

前端 未结 3 1246
温柔的废话
温柔的废话 2021-02-19 08:18

I am having a difficult time trying to bind my property which is of type List to my combobox through XAML.

public List MyProperty  { get; set; }
         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 08:36

    If you don't specify anything than just the path, the binding assumes as a source the container DataContext. By the way, the useful property is defined on the container (e.g. the window).

    You may solve it as follows (in the xaml):

    ItemsSource="{Binding Path=MyProperty, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"
    

提交回复
热议问题