简体   繁体   中英

XAML markup error when binding List<string> to a ComboBox ItemSource in a WPF

I'm trying to implement MVVM in a WPF app but am hitting a weird issue where List<string> is apparently being treated as a string and breaks the XAML designer.

from the XAML:

<ComboBox Grid.Row="0" 
          Grid.Column="1" 
          Name="ServerListComboBox" 
          HorizontalAlignment="Stretch" 
          VerticalAlignment="Top" 
          Margin="10" 
          Padding="5" 
          ItemsSource="Bind ServerList"/>

from the ViewModel:

public List<string> ServerList
{
    get { return model.ServerList; }
    set
    {
        model.ServerList = value;
        OnPropertyChange(nameof(ServerList));
    }
}

from the model:

 public List<string> ServerList { get; set; }

The designer says Invalid Markup and produces this error:

Error XDG0028 The TypeConverter for "IEnumerable" does not support converting from a string.

Clearly it's a List<string> not a string and compilation is fine, but I can't use the XAML Designer anymore. Is there something simple I'm overlooking to make the designer work again? Thanks for any advice, tips, or help

Change:

ItemsSource="Bind ServerList"

to:

ItemsSource="{Binding ServerList}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM