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 7947407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:25:24+00:00 2026-06-04T01:25:24+00:00

Is there a way to call methods from the view from the view model?

  • 0

Is there a way to call methods from the view from the view model? Is this good practice to do so? If not, how would I hide elements in the view from the view model? I’m just a bit confused because I’m used to working with ASP.Net, with code behind, etc.

xaml.cs

btnsave.visibility = visibility.hidden;
btnclose.visibility = visibility.hidden;
  • 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-04T01:25:26+00:00Added an answer on June 4, 2026 at 1:25 am

    For your specific example of hiding elements in the view, you probably want to set up some properties in the ViewModel that define the conditions under which those elements are visible. Then you bind the Visibility property (with a BooleanToVisibilityConverter, most likely) of those elements in the View to those properties in the ViewModel.

    More generally, you want to keep the direct coupling between them minimal if you can, but sometimes “reality” gets in the way. I’ve had some cases where I’ve passed in the View to the constructor of the ViewModel. Other cases where it’s been an interface that the View implements and that gets passed into the ViewModel. So there are options. But you should make sure you HAVE to go that route before doing it.

    Example:

    XAML:

    <Window ...>
        <Window.Resources>
            <BooleanToVisibilityConverter x:Key="_B2VC" />
        </Window.Resources>
        <StackPanel>
            <Button Content="Save" Visibility="{Binding IsSaveButtonVisible}" />
            <Button Content="Close" Visibility="{Binding IsCloseButtonVisible}" />
        </StackPanel>
    </Window>
    

    ViewModel:

    public class ViewModel: INotifyPropertyChanged
    {
    
        #region INPC Stuff
        public event PropertyChangedEventHandler PropertyChanged;
    
        private void RaisePropertyChanged(String propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    
        private bool _IsSaveButtonVisible;
        public bool IsSaveButtonVisible
        {
            get { return _IsSaveButtonVisible; }
            set
            {
                if (_IsSaveButtonVisible != value)
                {
                    _IsSaveButtonVisible = value;
                    RaisePropertyChanged("IsSaveButtonVisible");
                }
            }
        }
    
        private bool _IsCloseButtonVisible;
        public bool IsCloseButtonVisible
        {
            get { return _IsCloseButtonVisible; }
            set
            {
                if (_IsCloseButtonVisible != value)
                {
                    _IsCloseButtonVisible = value;
                    RaisePropertyChanged("IsCloseButtonVisible");
                }
            }
        }
    }
    

    Then your ViewModel changes those properties in response to whatever it needs to (say for instance Save is only valid if they’ve changed something – once that something is changed, the property on the ViewModel gets updated and bam, that gets propogated to the View.

    If you need further examples, i’d just suggest going and reading on MVVM. It takes a bit to grok, but its awesome once in use.

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

Sidebar

Related Questions

Is there a way to call multiple methods from backing bean in JSF? I
Is there a way in Java to call methods from the console? I know
Is there a way to create C# objects and call methods from unmanaged C++,
Is there a way to call Static Classes / Methods by name? Example: $name
The b.GetPixel call in this method is pretty slow, is there a way to
Is there a way to call an external script or program from Flash CS3
What is a good practice to implement MMVM with WCF Services? The View model
Opah! Is there any way I can call a method in the controller through
Quick question, is there a way to call your main method whatever you like
Is there a way to pass a call back function in a Java method?

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.