Click here to Skip to main content
15,887,370 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Microsoft Expression Blend 4 Pin
Abhinav S16-Jun-11 21:39
Abhinav S16-Jun-11 21:39 
Questiongnn?? "To view this content, please install: Microsoft Silverlight" Pin
Super Lloyd14-Jun-11 20:36
Super Lloyd14-Jun-11 20:36 
QuestionWeird scrollbar behaviour in DataGrid when manipulating single Row Visibility Pin
Durango6613-Jun-11 23:54
Durango6613-Jun-11 23:54 
AnswerRe: Weird scrollbar behaviour in DataGrid when manipulating single Row Visibility Pin
Mycroft Holmes14-Jun-11 1:14
professionalMycroft Holmes14-Jun-11 1:14 
GeneralRe: Weird scrollbar behaviour in DataGrid when manipulating single Row Visibility Pin
Durango6614-Jun-11 1:34
Durango6614-Jun-11 1:34 
QuestionButton in DataGridTemplateColumn throws ArgumentOutOfRangeException Pin
humble.apprentice13-Jun-11 10:13
humble.apprentice13-Jun-11 10:13 
QuestionHow to properly size ElementHost Pin
xusword13-Jun-11 8:28
xusword13-Jun-11 8:28 
QuestionProperty in ViewModel not displayed in View [modified] Pin
kurmanc13-Jun-11 5:07
kurmanc13-Jun-11 5:07 
Hi,

I have a ViewModel called MainWindowViewModel. In this I have a property that shows a modal window when an error occurs. This works fine as long as an error occurs during start-up.

When an error occurs after start-up, in SubViewModel, I invoke the parametrized constructor in MainWindowViewModel.

MainWindowViewModel.cs
public MainWindowViewModel()
{
    if (!isServerRunning)
    {
        this.ModalWindow = new LogViewModel("Service is down.");
    }
    else
    {
        this.ModalWindow = new LogViewModel();
    }
}

public MainWindowViewModel(string logMessage)
{
    this.ModalWindow = new LogViewModel(logMessage);
}

public LogViewModel ModalWindow
{
    get
    {
        return _modalWindow;
    }
    set
    {
        _modalWindow = value;

        OnPropertyChanged("ModalWindow");
    }
}


MainWindow.xaml
....
<Grid>
    <vw:LogView Content="{Binding Path=ModalWindow}"/>
</Grid>


- MainWindowViewModel is bound to MainWindow.xaml

- SubViewModel is bound to SubView.xaml

- MainWindow.xaml loads multiple views, one of them is SubView.

In App.xaml I have created an instance of the ViewModel and bound it to MainWindow.

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);
    MainWindow mainWindow = new MainWindow();
    MainWindowViewModel viewModel = new MainWindowViewModel();
    mainWindow.DataContext = viewModel;
    mainWindow.Show();
}


What I realized was that the modal window shows up when an error occurs after start-up if I create the modal window property in SubViewModel and bind it to SubView. But this is not ok since SubView is only a DockPanel covering 1/4 of the MainWindow. I.e. 1/4 is only covered with a modal window instead of the whole MainWindow.

I am not sure why modal window does not appear in MainWindow when I call the parametrized constructor from SubViewModel. When I debug I see that the part "_modalWindow = value;" has correct values but in any case the modal window does not show up.

I am binding the ViewModel to the Datacontext of the MainWindow. That's is probably why I see the Modal window when error occurs on start-up. For errors after start-up: Must I (from SubViewModel where I invoke the parametrized constructor in MainWindowViewModel) do some kind of binding to the datacontext of the Mainwindow again? How is the best way of doing this without having to create a new instance of MainWindow? Because MainWindow should only be created once.

Any help is much appreciated.

modified on Tuesday, June 14, 2011 4:33 AM

AnswerRe: Property in ViewModel not displayed in View Pin
kurmanc14-Jun-11 2:08
kurmanc14-Jun-11 2:08 
QuestionReferencing resources in an external assembly Pin
RugbyLeague13-Jun-11 4:07
RugbyLeague13-Jun-11 4:07 
AnswerRe: Referencing resources in an external assembly Pin
SledgeHammer0113-Jun-11 10:01
SledgeHammer0113-Jun-11 10:01 
GeneralRe: Referencing resources in an external assembly Pin
RugbyLeague13-Jun-11 21:21
RugbyLeague13-Jun-11 21:21 
QuestionThe property or field has not been initialized. Pin
bhavnvyas13-Jun-11 1:21
bhavnvyas13-Jun-11 1:21 
QuestionStyle for Current Page of Datapager. Pin
www.Developerof.NET10-Jun-11 1:40
www.Developerof.NET10-Jun-11 1:40 
AnswerRe: Style for Current Page of Datapager. Pin
Mark Salsbery10-Jun-11 6:46
Mark Salsbery10-Jun-11 6:46 
GeneralRe: Style for Current Page of Datapager. Pin
www.Developerof.NET10-Jun-11 18:01
www.Developerof.NET10-Jun-11 18:01 
QuestionMoving Data from Silverlight to ASp.net via SQl server Pin
Vimalsoft(Pty) Ltd9-Jun-11 9:20
professionalVimalsoft(Pty) Ltd9-Jun-11 9:20 
AnswerRe: Moving Data from Silverlight to ASp.net via SQl server Pin
Mark Salsbery9-Jun-11 10:33
Mark Salsbery9-Jun-11 10:33 
GeneralRe: Moving Data from Silverlight to ASp.net via SQl server Pin
Vimalsoft(Pty) Ltd9-Jun-11 19:06
professionalVimalsoft(Pty) Ltd9-Jun-11 19:06 
GeneralRe: Moving Data from Silverlight to ASp.net via SQl server Pin
Mark Salsbery9-Jun-11 19:10
Mark Salsbery9-Jun-11 19:10 
GeneralRe: Moving Data from Silverlight to ASp.net via SQl server Pin
Vimalsoft(Pty) Ltd9-Jun-11 19:14
professionalVimalsoft(Pty) Ltd9-Jun-11 19:14 
GeneralRe: Moving Data from Silverlight to ASp.net via SQl server Pin
Mark Salsbery10-Jun-11 6:10
Mark Salsbery10-Jun-11 6:10 
AnswerRe: Moving Data from Silverlight to ASp.net via SQl server Pin
Mycroft Holmes9-Jun-11 14:15
professionalMycroft Holmes9-Jun-11 14:15 
GeneralRe: Moving Data from Silverlight to ASp.net via SQl server Pin
Vimalsoft(Pty) Ltd9-Jun-11 19:11
professionalVimalsoft(Pty) Ltd9-Jun-11 19:11 
QuestionWPF Code Creation of input Binding Pin
Ed Hill _5_9-Jun-11 0:32
Ed Hill _5_9-Jun-11 0:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.