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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:57:25+00:00 2026-05-23T07:57:25+00:00

I want to change the visibility of a stack panel using the view model

  • 0

I want to change the visibility of a stack panel using the view model approach in my WP app , i am having problem , here is my code (sample).

Xaml Page:

<phone:PhoneApplicationPage 
x:Class="NextUKWindowsPhone.test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:localHelpers="clr-namespace:NextUKWindowsPhone.Helpers"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
    <localHelpers:BooleanToVisibilityConverter x:Key="MyBooleanToVisibilityConverter" />
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->

    <StackPanel>


    </StackPanel>
    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <StackPanel>
            <StackPanel  Name="prgrs"  Visibility="{Binding isVisible, Converter={StaticResource MyBooleanToVisibilityConverter}}" >
            <TextBlock Height="30" Name="textBlock1" Text="Hello...! show/hide me" />
        </StackPanel>
        <StackPanel>
            <Button Content="Hide" Height="72" Name="button2" Width="160" />
            <Button Content="Show" Height="72" Name="button1" Width="160" />
            </StackPanel>
        </StackPanel>
    </Grid>
</Grid>

Code Behind:

  public partial class test : PhoneApplicationPage
{
    public test()
    {
        InitializeComponent();
        DataContext = App.TviewModel;
    }
}

Converter Class:

 public  class BooleanToVisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var flag = false;
        if (value is bool)
        {
            flag = (bool)value;
        }
        else if (value is bool?)
        {
            var nullable = (bool?)value;
            flag = nullable.GetValueOrDefault();
        }
        if (parameter != null)
        {
            if (bool.Parse((string)parameter))
            {
                flag = !flag;
            }
        }
        if (flag)
        {
            return Visibility.Visible;
        }
        else
        {
            return Visibility.Collapsed;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var back = ((value is Visibility) && (((Visibility)value) == Visibility.Visible));
        if (parameter != null)
        {
            if ((bool)parameter)
            {
                back = !back;
            }
        }
        return back;
    }
} 

View Model:

public class testviewModel : INotifyPropertyChanged
{
    public bool isVisible  {get;set;}
    public testviewModel()
    {
        this.isVisible = true;
    }
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        if (null != PropertyChanged)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    public void show()
    {
        this.isVisible = true;
    }
    public void hide()
    {
        this.isVisible = false;
    }
}

in App.cs

 private static testviewModel tviewModel = null;
    public static testviewModel TviewModel
    {
        get
        {
            if (tviewModel == null)
                tviewModel = new testviewModel();

            return tviewModel;
        }
    }
  • 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-05-23T07:57:26+00:00Added an answer on May 23, 2026 at 7:57 am

    The problem is that the property that you have bound to does not raise property change in your ViewModel.

    Try to change it like this in you View Model:

    public bool isVisible  
    {
        get { return _isVisible; }
        set 
        {
            _isVisible = value;
            NotifyPropertyChanged("isVisible");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp:checkbox control, and I want to change the visibility of a
I want to change the font I am using in a CEikLabel on S60
I am using the new Google Maps v3 STYLED MAP. I want to change
[selectorView setFrame:CGRectOffset([selectorView frame], 0, -selectorView.frame.size.height)] In the above code I want to change the
I want to change controls visibility on c#, but nothing happens. The controls are
I want to change the visibility of the map ( roads and other labels
I want to change the visibility of a textbox, according to the value selected
I have a ddl control. I want to change the visibility of some items
In my wpf app i want to update a line on the canvas(change the
Here is the problem : I want to create reactive zones on a image

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.