我有一个组合框,复选框存在于组合框内。我想要多选复选框的值。我的代码:如何获取组合框WPF内的复选框的值?
<ComboBox Name="LocationFilterComboBox" Width="100" SelectedItem="{Binding LocationValue}">
<ComboBox.ItemTemplate >
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<CheckBox Content="{Binding LocationValue}" IsChecked="{Binding ElementName=all, Path=IsChecked, Mode=TwoWay}" Width="120" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
后端代码:
//code to get the value
public partial class Location
{
#region Property
private string LOCAID;
public string LocaId
{
get
{
return LOCAID;
}
set
{
value = LOCAID;
}
}
private string LOCADESC;
public string LocationValue
{
get
{
return LOCADESC;
}
set
{
value = LOCADESC;
}
}
#endregion
}
}
//code for binding the location
public IList<Location> BindAllLocation()
{
if (Repository != null) Repository.Dispose();
Repository = GetInvoiceRepository();
IList<Location> locationList = Repository.GetLocations(((App)Application.Current).DataContextFactory);
return locationList;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LocationFilterComboBox.ItemsSource = BindAllLocation();
}
我不明白你的问题。您已经在使用绑定。你的价值应该在属性'IsChecked'假设你的绑定;) –
一个共享的代码示例 我怎样才能检索被检查的项目@MightyBadaboom –
@AkhilJain请发布代码,我们可以使用的示例。 – lightlike