Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7787573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:42:50+00:00 2026-06-01T20:42:50+00:00

I’ve been online for days trying to figure this one out and, while I’ve

  • 0

I’ve been online for days trying to figure this one out and, while I’ve gotten a lot of insight into what and how ObjectDataProviders work, I am still unable to solve this one… I am trying to us an ObjectDataProvider to access a method in my viewmodel. After the selection has been changed in a combobox, this method is supposed to check to see if the form data has been edited. If it has, the user will be asked if they would like to save the edited information before the selection changes. I can’t seem to tie the two together – the list for the combobox and the method… I can get the combobox working, but only if I specify ItemsSource and SelectedItem verbatim. These values are the basis for the rest of my form information being loaded. If you can’t tell, I’m a newbie and this one just won’t come to me. One more explanation and then I’ll get to the code. My app is structured in layers – I have MainWindow, which calls PERListView, which calls EvalItemView. Each View is based on a ViewModel, i.e, MainWindow uses AppVM, PERListView uses PERListVM, and EvalItemView uses EvalItemVM. The combobox I’m having trouble with is in MainWindow while the data being edited is in EvalItemView. Thus I am trying to use the ObjectDataProvider to get ahold of the SelectedNewPERListItem method in AppVM. This method checks to see if edits have been made, asks the user if they wish to save the changes and then is supposed to return the list that is used by the ComboBox. It should be noted that what is currently working in the combobox as the ItemsSource is a ObservableCollection. And the SelectedItem (SelectedList) is of type PERListVM.

OK…
The ObjectDataProvider:

xmlns:viewmodel="clr-namespace:PERTrack.ViewModel"

<Window.Resources>

    <ObjectDataProvider x:Key="PERListProvider" ObjectType="{x:Type viewmodel:AppVM}" 

MethodName=”SelectNewPERListItem” >

        <ObjectDataProvider.MethodParameters>

            <sys:Int32>1</sys:Int32>

        </ObjectDataProvider.MethodParameters>

    </ObjectDataProvider> 

</Window.Resources>

The ComboBox:

SelectedItem="{Binding SelectedList}" IsSynchronizedWithCurrentItem="True" Background="WhiteSmoke" >
<ComboBox.SelectedValue>
    <Binding Source="{StaticResource PERListProvider}" BindsDirectlyToSource="True" 
      UpdateSourceTrigger="PropertyChanged" Mode="OneWay" />
</ComboBox.SelectedValue>
<ComboBox.ItemTemplate>
   <DataTemplate>
      <TextBlock Text="{Binding Path=PERList_ListID}" />
   </DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemContainerStyle>
    <Style TargetType="ComboBoxItem">
      <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    </Style>
</ComboBox.ItemContainerStyle>
</ComboBox>

The SelectNewPERListItem method in the AppVM viewmodel:

    private PERListVM SelectNewPERListItem(object noParam)
    {
        if (_SelectedList != null)
        {
            if (_SelectedList.SelectedItem != null)
            {
                if (_SelectedList.SelectedItem.IsDirty)
                {
                    System.Windows.Forms.DialogResult SaveEval;
                    SaveEval = System.Windows.Forms.MessageBox.Show("Do you wish to save your updates?", "User Action", System.Windows.Forms.MessageBoxButtons.YesNo);

                    // the user wants to save the updated information
                    if (SaveEval == System.Windows.Forms.DialogResult.Yes)
                    {
                        App.context.SaveChanges();
                    }
                }
            }
        }

        return _SelectedList;
    }

I know I’m missing something, but what it is I don’t know…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:42:52+00:00Added an answer on June 1, 2026 at 8:42 pm

    I don’t know anything about ObjectDataProvider, but I’d approach this another way.

    Let’s say MainWindow is a WPF Window, the rest of your views are UserControls. The MainWindow ViewModel (AppVM) would have a property for the PERListVM, and in the XAML for the MainWindow, and set the DataContext for PERListView to the PERListVM property.

    The ComboBox SelectedItem binds a property on the AppVM, so in the setter of this property, call a method or check a property on the PERListVM if the form data has been edited.

    Let me know via a comment if this isn’t clear.

    BTW, you should also rethink your approach with the MessageBox. Calling MessageBox.Show() doesn’t sit too well with MVVM, but that’s a seperate problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.