我想要一个绑定到集合的复选框列表。So when options are selected, they are added to the list --- when options are deselected, they get removed.
尝试了多种方法,但未能解决此问题。
模型
public enum WeatherType
{
Rainy,
Sunny,
Cloudy,
Windy
}
视图模型
public class WeatherViewModel : INotifyPropertyChanged
{
public ObservableCollection<WeatherType> WeatherTypes {get;set;}
...
}
XAML
<ObjectDataProvider x:Key="weather"
MethodName="GetValues"
ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="business:WeatherType" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
...
<ItemsControl Grid.Row="4"
Grid.Column="1"
ItemsSource="{Binding Source={StaticResource weather}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Content="{Binding}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>