locked
Combo Box Select Value doesn't clear when object in View Model is set to new instance RRS feed

  • Question

  • I have several combo boxes bound back to an object in my View Model.

     

    <toolkit:DataField Label="{Binding Path=VirtualTerminalStrings.DocTypeLabel, Source={StaticResource ResourceWrapper}}" x:Name="DocTypeLookUp" IsRequired="True">
       <ComboBox DisplayMemberPath="DisplayText" ItemsSource="{Binding Path=DocType, Source={StaticResource ComboBoxServices}, Mode=TwoWay}" SelectedValuePath="Key" SelectedValue="{Binding Path=ProcessorRequest.C_DOCUMENT_TYPE_ID, Mode=TwoWay}"/>
    </toolkit:DataField>
     
    I also have a Cancel button thats purpose is to reset all populated values in the UI.  This Cancel button is custom and handled inside the View Model as well.
     
    When the Cancel button is clicked, I am assigning a new instance of an object to the ProcessorRequest property to clear out all fields bound to the ProcessorRequest. 
     
    public void ResetUI()
            {
                // TODO: Determine what should happen when the user says they want to submit changes.
                // Use this placeholder message in the meantime.
                if (MessageBox.Show("Clear All Populated Fields?", "Confirm Refresh", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    // Clears Payment Request Line DataGrid and resets the line count
                    PayRequestLines.Clear();
                    LineCount = 0;
    
                    // Creates new objects for field binding so that screen will clear
                    ProcessorRequest = new pay_processor_request();
                    CreditCard = new pay_credit_card();
                }
            }
      The first time Cancel is clicked, everything works fine and all Text Boxes and Combo Boxes clear out. The second time I would click Cancel, only the Text Boxes clear out but the Combo Boxes remain populated. Any ideas as to why this behavior would happen? Thanks.
    Monday, May 3, 2010 11:31 AM