0
votes

I am using MVVM Light WPF 4.

I have a ContentPresenter in my Home.xaml.

<ContentPresenter Name="MDI" Content="{Binding WindowName, Mode=OneWay}">

I am binding user control to this in viewmodel like

public UserControl WindowName { get; set; }
    void ShowSalesEntry()
    {
        WindowName = null;
        WindowName = new SalesEntry();
        RaisePropertyChanged("WindowName");
    }

by using command in a menu click and it is binding fine.

Now in the user control i have a button which i used to close (but to close i change the visibility to collapsed) by this way..

Visibility="{Binding visibility, Mode=OneWay}"

in the user control view model,

public SalesEntryViewModel()
    {
        visibility = Visibility.Visible;            
        cmdExitWindow = new RelayCommand(ExitWindow);
        RaisePropertyChanged("visibility");
    }

and the following to close (visibility to collapsed)

public RelayCommand cmdExitWindow { get; set; }

    void ExitWindow()
    {
        visibility = Visibility.Hidden;
        RaisePropertyChanged("visibility");
    }

To exit (means visibility collapsed).. This is working fine upto this.

Problem is when i click the same page i mean to show the same user control, now this time the visibility is still collapsed. Even though i changed to visible in the load event.

How to solve this.. I am new to MVVM WPF.. Please help me..

1

1 Answers

1
votes

Problem is when i click the same page i mean to show the same user control, now this time the visibility is still collapsed. Even though i changed to visible in the load event.

Based on this comment and the code provided, you've either omitted code, or you've confused the purpose of the constructor.

In your constructor, you have set the Visibility to Visible. You then have a method that sets the Visibility to Hidden, but there is nothing to ever set it back to Visible once this has occurred. The constructor only fires when the object is created. You need something to set the Visibility back at the appropriate time (ie. your comment "when i click the same page").

//Add these lines to the method/event that will show the control again
visibility = Visibility.Visible;
RaisePropertyChanged("visibility");

That's the best answer I can give based on what you've provided.