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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:36:29+00:00 2026-06-18T06:36:29+00:00

I have a Border with Label inside a Window , <Border x:Name=Border1 BorderBrush=Black BorderThickness=1

  • 0

I have a Border with Label inside a Window,

<Border x:Name="Border1" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="21" Margin="229,164,0,0" VerticalAlignment="Top" Width="90" Opacity="0.5">
    <Grid>
        <Label Content="test"/>
    </Grid>
</Border>

I have also a Variable:

public bool vis = false;

How could I bind the vis variable with border Visibility property?

  • 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-18T06:36:30+00:00Added an answer on June 18, 2026 at 6:36 am

    If you already have your bool variable in a viewmodel, you have two things to do:

    1. make it a property, like:

      public bool vis { get; set; }

    And you need a visibility converter for your property then:

    It is described here:

    http://social.msdn.microsoft.com/Forums/en/wpf/thread/3c0bef93-9daf-462f-b5da-b830cdee23d9

    The example assumes that you have a viewmodel and use Binding

    Here is some demo code that I made from your snippet:

    ViewModel:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    
    namespace StackOverflowWpf2
    {
        public class BorderViewModel : INotifyPropertyChanged
        {
            private bool borderVisible = false;
    
            public bool BorderVisible 
            {
                get
                {
                    return borderVisible;
                }
    
                set
                {
                    borderVisible = value;
                    NotifyPropertyChanged("BorderVisible");
                }
            }
    
            private void NotifyPropertyChanged(string info)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(info));
                }
            }
    
            public event PropertyChangedEventHandler PropertyChanged;
        }
    }
    

    XAML:

    <Window x:Class="StackOverflowWpf2.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <BooleanToVisibilityConverter x:Key="BoolToVisConverter" />
        </Window.Resources>
        <Grid>
            <Border x:Name="Border1" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="21" Margin="229,164,0,0" VerticalAlignment="Top" Width="90" Opacity="0.5"
                    Visibility="{Binding Path=BorderVisible, Converter={StaticResource BoolToVisConverter} }" >
                <Grid>
                    <Label Content="test"/>
                </Grid>
            </Border>
            <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="381,35,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" 
                    />
        </Grid>
    </Window>
    

    Some Codebehind quick testcode: (actually is MainWindow.xaml.cs)

    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;
    
    namespace StackOverflowWpf2
    {
        /// <summary>
        /// Interaktionslogik für MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public BorderViewModel ViewModel { get; set; }
    
            public MainWindow()
            {
                InitializeComponent();
    
                ViewModel = new BorderViewModel();
    
                this.DataContext = ViewModel;
    
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                var vis = (this.DataContext as BorderViewModel).BorderVisible;
    
                (this.DataContext as BorderViewModel).BorderVisible = !vis;
    
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two divs one inside another. I have given some border to both
How can I draw a rectangle that have a black border and white background?
I have a window with a solid border around it. How can I remove
I have a label inside of a div. I want to position the label
So I have the html code: <fieldset> <legend>Log On</legend> <div class=altregrow> <label for=UserName>User name</label>
I have a window with widgets inside it. When I re-size the window manually,
I have a simple windows form with no border and several label controls (nothing
I have a border layout whose center panel is defined like the below. {
I have a border layout in ExtJS, The north region contains some HTML, but
I would like to have a border that is 4px thick pink on the

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.