Good afternoon, there is a Class with properties and sampling:
public partial class Register : Window { public int Id { get; set; } public string Name { get; set; } public ObservableCollection<Roles> ItemsForRoles { get; set; } public Register() { DbModelContainer db = new DbModelContainer(); ObservableCollection<Roles> ItemsForRoles = new ObservableCollection<Roles>(); var query = db.RolesSet.ToList(); foreach (var roles in query) { ItemsForRoles.Add( new Roles { Id = roles.Id, Name = roles.Name } ); } } } And ComboBox:
<ComboBox Name="role" ItemsSource="{Binding ItemsForRoles}"> <ComboBoxItem Content="{Binding Name}"></ComboBoxItem> </ComboBox> Tell me, please, how in the XAML code to correctly bind the data to the ComboBox, so that all entries are displayed, not just one. It is necessary to remove from the database the entries in this ComboBox and the passed parameter to make Id, not Name.
Resolving a question from recent comments (setting IsEnabled = false to the first (selected) item):
<ComboBox.ItemContainerStyle> <Style TargetType="ComboBoxItem"> <Style.Triggers> <DataTrigger Binding="{Binding Id}" Value="-1"> <Setter Property="IsEnabled" Value="False"/> </DataTrigger> </Style.Triggers> </Style> </ComboBox.ItemContainerStyle>