WPF Binding List
Вот такая картина
public class Config
{
public String Key { get; set; }
public String ValueConfig { get; set; }
}
public class ConfigTemplates : INotifyPropertyChanged
{
private String title;
private List<Config> configs;
public String Title
{
get => title;
set
{
title = value;
OnPropertyChanged(nameof(Title));
}
}
public List<Config> Configs
{
get => configs;
set
{
configs = value;
OnPropertyChanged(nameof(Configs));
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public sealed class ApplicationViewModelContext : INotifyPropertyChanged
{
private ConfigTemplates selectedConfig;
public ObservableCollection<ConfigTemplates> Configs { get; set; }
public ConfigTemplates SelectedConfig
{
get => selectedConfig;
set
{
selectedConfig = value;
OnPropertyChanged(nameof(SelectedConfig));
}
}
public ApplicationViewModelContext()
{
Configs = new ObservableCollection<ConfigTemplates>()
{
new ConfigTemplates()
{
Title = "XXX",
Configs = new List<Config>()
{
new Config {Key = $"1", ValueConfig = $@"XXX1"},
new Config {Key = $"2", ValueConfig = $@"XXX2"},
new Config {Key = $"3", ValueConfig = $@"XXX3"}
}
}
};
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ListBox Grid.Column="0" ItemsSource="{Binding Configs}" SelectedItem="{Binding SelectedConfig}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="5">
<TextBlock FontSize="18" Text="{Binding Path=Title}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Grid.Column="1" DataContext="{Binding SelectedConfig}">
<TextBlock Text="Selected Settings"/>
<TextBlock Text="Title"/>
<TextBox Text="{Binding Title, UpdateSourceTrigger=PropertyChanged}"/>
<-- НЕ работает --!>
<ListBox ItemsSource="{Binding Configs, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
</Grid>
как можно вывести данные Configs
<ListBox ItemsSource="{Binding Configs, UpdateSourceTrigger=PropertyChanged}"/>
То есть, слева отображается Title, при нажатии на него, справа должны отобразится данные из Configs .
Работает, Title отображается, но Configs отображаются не правильно.Как можно вывести Key = $"1", ValueConfig = $@"XXX1"
