Checkbox in Wizard not updating

Wizard for WPF Forum

Posted 12 years ago by Pat Maneely - Software Engineering Manager, Cobham Aerospace
Version: 11.1.0545
Avatar

I have a wizard of several pages, all of which contain property grids which are populated by a datafactory.  So, the XAML looks like this:

    <ScrollViewer>
        <wizard:Wizard x:Name="fctConfigSetupWizard" WindowTitleBehavior="PageTitle" WindowTitleBaseText="Configuration Wizard" 
                   PageSequenceType="Stack"
                   IsWindowDialogResultUpdatingEnabled="True"
                   HelpButtonVisible="False" 
                   FinishButtonEnabled="{Binding ValidConfig}">
            <wizard:WizardPage x:Name="msmFSPPage"  PageType="Interior"
                           Caption="Caption of page"
                           Description="Description of page" 
                           Title="Title of Page"
                           HelpButtonVisible="False"
                           NextButtonEnabled="{Binding Path=FlexCommSysData.P25CapableSystem}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Label Content="Configuration Name" Height="23.277" VerticalAlignment="Top" />
                    <TextBox Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" 
                         MaxLines="1" Margin="-75,0,0,0" HorizontalAlignment="Stretch" Width="Auto" 
                         Text="{Binding Path=FlexCommSysData.Name}"/>

                    <propgrid:PropertyGrid Name="fctSysDataPG" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" 
                                       Width="Auto" Height="Auto"
                                       IsSummaryVisible="True"
                                       propgrid:PropertyGrid.IsAsynchronous="False"
                                       SelectedObject="{Binding Path=FlexCommSysData}">
                        <propgrid:PropertyGrid.Resources>
                            <Style x:Key="{x:Type propgrid:PropertyGridDataAccessorItem}" TargetType="{x:Type propgrid:PropertyGridDataAccessorItem}"
                               BasedOn="{StaticResource fctSysDataPgStyle}" />
                        </propgrid:PropertyGrid.Resources>
                        <propgrid:PropertyGrid.DataFactory>
                            <RpWin:CustomDataFactory />
                        </propgrid:PropertyGrid.DataFactory>
                    </propgrid:PropertyGrid>
                </Grid>
            </wizard:WizardPage>
        </wizard:Wizard>
    </ScrollViewer>

 And then in the class "FlexcommSystemData" are all the properties, one of which is a boolean.  What I want to happen is when this boolean is set true (the box is checked) a message box will pop up asking the user if they really want to click this.  I've hooked this into the property, and that part works fine.  The issue is if the user clicks "No" to the message box (don't want to do this) the box still shows checked even though the underlying boolean property is false... so somehow the UI is getting out of sync.  If you click forward in the wizard and back again to get the page to refresh, the check box displays correctly.  The property looks like this:

        [Category("C-5000")]
        [Description("Select whether to enforce the FCC narrowbanding mandate or not")]
        [DisplayName("Enforce Narrowband")]
        public bool NarrowBanding
        {
            get { return (model_.NarrowBanding == CfgData.TNarrowBanding.NarrowBanding) ? true : false; }
            set 
            {
                if (value)
                {
                    model_.UserWantsNarrowbanding();
                }
                else
                    model_.NarrowBanding = CfgData.TNarrowBanding.NotNarrowBanding;
                
                NotifyPropertyChanged("NarrowBanding"); 
            }
        }

 The UserWantsNarrowBanding() method is what pops up the box and can modify the underlying value.  You can see at the end, it calls NotifyPropertyChanged() which generates a PropertyChangedEvent.  My question is, why is this not sufficient to update the UI?  I suspect it has something to do with the fact that this is happening in the middle of the checkbox tick itself, but I'm not sure where else to hook this in at.  Any ideas would be greatly apprciated.  Thanks!  

Comments (2)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Pat,

My guess would be that you are modifying the property value in response to a checked changed event and that is possibly causing things to come out of sync.  Perhaps you could try doing a Dispatcher.BeginInvoke call around your UserWantsNarrowBanding() method call so that it happens outside of the root event handler?  I would think that that would work around the problem.


Actipro Software Support

Posted 12 years ago by Pat Maneely - Software Engineering Manager, Cobham Aerospace
Avatar

Yep, that did the trick!  Thanks!!  For anyone else who might run into this, the modified code is pasted below. This is using the MVVM architecture, so the viewDispatcher_ is passed in from the view to the view model. 

        public bool NarrowBanding
        {
            get { return (model_.NarrowBanding == CfgData.TNarrowBanding.NarrowBanding) ? true : false; }
            set 
            {
                if (value)
                {
                    if (viewDispatcher_ != null)
                        viewDispatcher_.BeginInvoke(DispatcherPriority.Normal, new NewThreadDelegate(PromptNarrowbandWarning));
                }
                else
                    model_.NarrowBanding = CfgData.TNarrowBanding.NotNarrowBanding;
                
                NotifyPropertyChanged("NarrowBanding"); 
            }
        }
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.