darthmaule2
Topic Author
Posts: 94
Joined: 23 Oct 2014, 19:54

Master-detail pattern works in WPF but does not seem to work in Noesis

25 Jul 2019, 19:21

I use this pattern to display settings in a WPF application. So, the UI is a split view, with settings "Categories" (the "master" in the pattern) on the left. The individual settings for a given Category (the "detail" in the pattern) are displayed on the right. As you select different categories on the left, different sets of settings are displayed on the right.

A basic implementation of this is:
SettingsView.xaml
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="350"></ColumnDefinition> // The left side displays categories of settings
            <ColumnDefinition Width="Auto"></ColumnDefinition> // The right side displays the set of settings for a given category
        </Grid.ColumnDefinitions>
        <ListBox Grid.Column="0" ItemsSource="{Binding Path=CategoryCollection}" >
        </ListBox>
        <Grid Grid.Column="1">
            <ContentPresenter Content="{Binding Path=CategoryCollection.CurrentItem.SettingsContainer, Mode=TwoWay}"></ContentPresenter>
        </Grid>
The CategoryCollection is populated like this:
        public ObservableCollection<CategoryContainer> CategoryCollection { get; }
        CategoryCollection = new ObservableCollection<CategoryContainer>()
            {
                {
                    new CategoryContainer(
                        new SettingsContainer(
                            new ObservableCollection<Setting>()
                            {
                                new Setting() { Name = "Setting #1" },
                                new Setting() { Name = "Setting #2" },
                                new Setting() { Name = "Setting #3" },
                            }), "Category #1")
                },
                {
                    new CategoryContainer(
                        new SettingsContainer(
                                new ObservableCollection<Setting>()
                                {
                                    new Setting() { Name = "Setting #4" },
                                    new Setting() { Name = "Setting #5" },
                                    new Setting() { Name = "Setting #6" },
                                }), "Category #2")
                }
            };
There is a CategoryContainer for each category on the right. Each of these holds a SettingsContainer, which is a user control containing a list bound to user settings
    public class CategoryContainer : NotifyObject
    {
        public CategoryContainer(UserControl settingsContainer, string name)
        {
            _settingsContainer = settingsContainer;
            _name = name;
        }

        private object _settingsContainer;
        public object SettingsContainer
        {
            get
            {
                return _settingsContainer;
            }
            set
            {
                _settingsContainer = value;
                OnPropertyChanged("SettingsContainer");
            }
        }


SettingsContainer.xaml is a UserControl with a ListBox bound to a list of settings:
    <ListBox
        ItemsSource="{Binding Path=SettingsCollection}">
    </ListBox>
 
darthmaule2
Topic Author
Posts: 94
Joined: 23 Oct 2014, 19:54

Re: Master-detail pattern works in WPF but does not seem to work in Noesis

25 Jul 2019, 19:26

Attempting to add minimal example attachment...
 
darthmaule2
Topic Author
Posts: 94
Joined: 23 Oct 2014, 19:54

Re: Master-detail pattern works in WPF but does not seem to work in Noesis

25 Jul 2019, 19:26

Attaching an example isn't working for me in any browser... could be my work's proxy. I'll try from home later.
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: Master-detail pattern works in WPF but does not seem to work in Noesis

25 Jul 2019, 20:45

Hi,

ObservableCollection<T> doesn't expose a CurrentItem property, so the binding {Binding Path=CategoryCollection.CurrentItem.SettingsContainer, Mode=TwoWay} cannot be resolved.

But you can set a name on the ListBox and then use it to bind to the SelectedItem property:
 <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="350"></ColumnDefinition> // The left side displays categories of settings
            <ColumnDefinition Width="Auto"></ColumnDefinition> // The right side displays the set of settings for a given category
        </Grid.ColumnDefinitions>
        <ListBox x:Name="Categories" Grid.Column="0" ItemsSource="{Binding Path=CategoryCollection}" />
        <Grid Grid.Column="1">
            <ContentPresenter Content="{Binding Path=SelectedItem.SettingsContainer, ElementName=Categories}" />
        </Grid>
This is how we do it in our QuestLog example: https://github.com/Noesis/Tutorials/blo ... .xaml#L305
 
darthmaule2
Topic Author
Posts: 94
Joined: 23 Oct 2014, 19:54

Re: Master-detail pattern works in WPF but does not seem to work in Noesis

25 Jul 2019, 21:07

That works great, thanks.

Who is online

Users browsing this forum: No registered users and 0 guests