Avatar of Matt Cartlidge
Matt CartlidgeFlag for United Kingdom of Great Britain and Northern Ireland asked on

XAML/WPF: How to get XAML to re-evaluate when using a ComboBox in a ListView

Hi,

I'm finding it tricky to find an answer for this as maybe I'm not wording my searches correctly.

I've got some fairly simple XAML whichs presents ListView items based on a class which uses the usual ObservableCollection and INotifyChanged.

ListView Combo drop down
Above you see one row in the Grid and the "Channel" combo is open with the options. You can't see it clearly (this is another problem I've got) but the last 8 items are actually disabled - only the first 4 items are enabled. Also the row itself is difficult to see - too bright - which is ANOTHER problem I have (asked separately but no answers as yet).

The XAML takes care of the enable/disable status depending on if the "Mode" combo is "Stereo" or "Mono". If "Stereo" is selected then the first 4 items are enabled and the rest are disabled.

I want the selection of "Mono" to do the opposite - disable the first 4 items and enable the rest.

My question is, how do I get the XAML to re-evaluate the "Channel" ComboBox? Or do I need to manage this in the code somehow?

Here's the ListView code.

                                    <ListView x:Name="ListViewOutputs" Style="{DynamicResource StyleListView}">
                                        <ListView.View>
                                            <GridView>
                                                <GridViewColumn Header="Enabled">
                                                    <GridViewColumn.CellTemplate>
                                                        <DataTemplate>
                                                            <CheckBox IsChecked="{Binding Enabled, Mode=TwoWay}" Style="{DynamicResource StyleCheckBox}"/>
                                                        </DataTemplate>
                                                    </GridViewColumn.CellTemplate>
                                                </GridViewColumn>
                                                <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
                                                <GridViewColumn Header="Mode">
                                                    <GridViewColumn.CellTemplate>
                                                        <DataTemplate>
                                                            <ComboBox x:Name="ComboBoxOutputMode" SelectionChanged="ComboBoxOutputMode_SelectionChanged" SelectedValuePath="Content" SelectedValue="{Binding Mode, Mode=TwoWay}" Style="{DynamicResource ComboBoxStyle}">
                                                                <ComboBoxItem Content="Stereo"/>
                                                                <ComboBoxItem Content="Mono"/>
                                                            </ComboBox>
                                                        </DataTemplate>
                                                    </GridViewColumn.CellTemplate>
                                                </GridViewColumn>
                                                <GridViewColumn Header="Monitor">
                                                    <GridViewColumn.CellTemplate>
                                                        <DataTemplate>
                                                            <CheckBox IsChecked="{Binding Monitor, Mode=TwoWay}" Style="{DynamicResource StyleCheckBox}"/>
                                                        </DataTemplate>
                                                    </GridViewColumn.CellTemplate>
                                                </GridViewColumn>
                                                <GridViewColumn Header="Channel">
                                                    <GridViewColumn.CellTemplate>
                                                        <DataTemplate>
                                                            <ComboBox x:Name="ComboBoxOutputChannel" DropDownOpened="ComboBoxOutputChannel_DropDownOpened"  SelectedValuePath="Content" SelectedValue="{Binding ChannelString, Mode=TwoWay}" Style="{DynamicResource ComboBoxStyle}">
                                                                <ComboBoxItem IsEnabled="{Binding IsModeStereo}" Content="Front"/>
                                                                <ComboBoxItem IsEnabled="{Binding IsModeStereo}" Content="Rear"/>
                                                                <ComboBoxItem IsEnabled="{Binding IsModeStereo}" Content="Center/Subwoofer"/>
                                                                <ComboBoxItem IsEnabled="{Binding IsModeStereo}" Content="Side"/>
                                                                <ComboBoxItem IsEnabled="{Binding IsModeMono}" Content="Front Left"/>
                                                                <ComboBoxItem IsEnabled="{Binding IsModeMono}" Content="Front Right"/>
                                                                <ComboBoxItem IsEnabled="{Binding IsModeMono}" Content="Rear Left"/>
                                                                <ComboBoxItem IsEnabled="{Binding IsModeMono}" Content="Rear Right"/>
                                                                <ComboBoxItem IsEnabled="{Binding IsModeMono}" Content="Center"/>
                                                                <ComboBoxItem IsEnabled="{Binding IsModeMono}" Content="Subwoofer"/>
                                                                <ComboBoxItem IsEnabled="{Binding IsModeMono}" Content="Side Left"/>
                                                                <ComboBoxItem IsEnabled="{Binding IsModeMono}" Content="Side Right"/>
                                                            </ComboBox>
                                                        </DataTemplate>
                                                    </GridViewColumn.CellTemplate>
                                                </GridViewColumn>
                                                <GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}"/>
                                            </GridView>
                                        </ListView.View>
                                    </ListView>

Open in new window

* WPF* xamlC#

Avatar of undefined
Last Comment
Matt Cartlidge

8/22/2022 - Mon
SOLUTION
ambience

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Matt Cartlidge

Thanks for your response.

It is becoming clearer now why this isn't working as I'd expect.

My code for the IsModeStereo method :-

        public bool IsModeStereo
        {
            get
            {
                if (Mode == MCOutputMode.Stereo) { return true; }
                return false;
            }
        }

Open in new window


You can probably guess what the IsModeMono method looks like so I won't post that.

This is the MCOutputMode which determines the result of IsModeMono and IsModeStereo.

        private MCOutputMode _Mode;
        public MCOutputMode Mode
        {
            get { return _Mode; }
            set
            {
                _Mode = value;
                OnPropertyChanged();
            }
        }

Open in new window


I've added the OnPropertyChanged() call for both IsModeMono and IsModeStereo. However, this causes an overflow, assuming because  they are stuck in a loop calling eachother.

Can you see what I'm doing wrong here? Happy to share more code if you think it's relevant.
ASKER CERTIFIED SOLUTION
ambience

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Matt Cartlidge

Works great! Thank you!

What is the purpose of => ?

I haven't seen that used before, but I am relatively new to C#
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Matt Cartlidge

All sorted, thanks!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck