C# application an error

Experts
In the code below I am facing this error as you can see in the picture.

Can anyone suggest me how in all the Show() ----what is the problem ?

The all the Show() functions are showing the same errors when I am clicking the button.

Thanking you


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

using AdventureWorks.WPF.Model;

namespace AdventureWorks.WPF
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        ModelDataContext DC = new ModelDataContext();
        public Window1()
        {
            InitializeComponent();

            WindowsListBox.ItemsSource = WindowViewStateManager.Instance.WindowViewStates;

        }

        private void SalesOrderButton_Click(object sender, RoutedEventArgs e)
        {
            SalesOrderWindow wnd = new SalesOrderWindow();
            
            wnd.DataContext = DC.SalesOrderHeaders;
            wnd.Show();
        }

        private void CustomerButton_Click(object sender, RoutedEventArgs e)
        {
            CustomerWindow wnd = new CustomerWindow();
            wnd.DataContext = DC.Customers;
            wnd.Show();
        }

        private void ProductButton_Click(object sender, RoutedEventArgs e)
        {
            ProductWindow wnd = new ProductWindow();
            wnd.DataContext = DC.Products;
            wnd.Show();            
        }
    }
}

Open in new window

Error.JPG
ANINDYAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SawinerCommented:
Opening a new window seem to work like a charm for me.

Try and provide more detail.

What happens inside the SalesOrderWindow class ?

What is the source stack of the exception?
does the exception has inner exception/inner messages/error codes ?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chuck YetterCommented:
That exception is thrown when a method call is invalid for the object's current state.  I'd say you need to set some breakpoints in the SalesOrderWindow's constructor and Show() methods and then step through it a line at a time and see what happens.  You'll probably find your error right away.

0
ANINDYAAuthor Commented:
the SaelsOrderWindow.xaml and the SalesOrderController.cs class is as followes
the  code of the SalesOrderController.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AdventureWorks.WPF
{
    public class SalesOrderController
    {
        public bool CanUpdateCurrent()
        {
            return false;
        }
        public bool CanDeleteCurrent()
        {
            return false;
        }
        
    }
}


the code of the salesOrderWindow.xaml

<Window x:Class="AdventureWorks.WPF.SalesOrderWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:AdventureWorks.WPF"
    local:WindowViewState.IsManaged="True"
        MinWidth="590" Width="590"
    Title="Sales Orders" >

    <Window.CommandBindings>
        <CommandBinding 
            Command="{x:Static local:Commands.NewSalesOrder}" 
            CanExecute="NewSalesOrder_CanExecute" 
            Executed="NewSalesOrder_Executed" />
        <CommandBinding 
            Command="{x:Static local:Commands.DeleteSalesOrder}" 
            CanExecute="DeleteSalesOrder_CanExecute" 
            Executed="DeleteSalesOrder_Executed" />
        <CommandBinding 
            Command="{x:Static local:Commands.UpdateSalesOrder}" 
            CanExecute="UpdateSalesOrder_CanExecute" 
            Executed="UpdateSalesOrder_Executed" />
    </Window.CommandBindings>
    
    
    
    <local:SalesOrderView />

</Window>

Open in new window

0
ANINDYAAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.