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

  • Home
  • SEARCH
  • 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 6166383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:19:46+00:00 2026-05-23T22:19:46+00:00

<Window x:Class=WpfApplication2.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=BooleanToVisibilityConverter/> </Window.Resources> <Grid Grid.IsSharedSizeScope=True> <Grid.RowDefinitions>

  • 0
<Window x:Class="WpfApplication2.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="BooleanToVisibilityConverter"/>
  </Window.Resources>

  <Grid Grid.IsSharedSizeScope="True">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto" SharedSizeGroup="FirstColumn"/>
      <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <ToggleButton Name="m_chkTest"
                  Grid.Row="0"
                  Grid.Column="1"                       
                  HorizontalAlignment="Left"
                  Content="Test"
                  Margin="4"/>
    <Grid Grid.Row="1" 
          Grid.ColumnSpan="2"
          Visibility="{Binding IsChecked, ElementName=m_chkTest, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>

      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" SharedSizeGroup="FirstColumn"/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>

      <Label Grid.Row="0" Grid.Column="0" Content="Test1"/>
      <Label Grid.Row="0" Grid.Column="1" Content="Test2"/>
      <Label Grid.Row="0" Grid.Column="2" Content="Test3"/>
    </Grid>
  </Grid>
</Window>

When I toggle the test toggle button, the content goes from left to centered (because of the new visible content). What I would like is that the toggle button is centered by default (because of the hidden content, not only because I change it horizontal alignment.

What occured

This image show the 3 states available. I achieve another state by clicking on the test toggle button. What I would not like to occur is the first one.

  • 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-23T22:19:46+00:00Added an answer on May 23, 2026 at 10:19 pm

    You need a different converter than BooleanToVisibility because that converter returns Collapsed for visibility rather than Hidden, like this:

    public class BoolHiddenConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is bool && ((bool)value))
                return Visibility.Visible;
            return Visibility.Hidden;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is Visibility && (Visibility)value == Visibility.Visible)
                return true;
            return false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

XAML <Window x:Class=WpfApplication1.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> <Grid> <DataGrid Height=117 HorizontalAlignment=Left Margin=43,12,0,0 Name=dataGrid1
Like so: <Window x:Class=WpfApplication3.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> <ResourceDictionary x:Key=whatever Source=colors.xaml />
WPF: <Window x:Class=WpfApplication1.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:WpfApplication1 Title=MainWindow Height=350 Width=525> <Window.Resources> <local:BooleanToVisibilityConverter x:Key=BooleanToVisibilityConverter True=Visible False=Collapsed
Why it is not working? The XAML: <Window x:Class=WpfApplication1.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=218 Width=239>
Consider following XAML: <Window x:Class=WpfApplication1.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> <StackPanel> <TextBlock Text={Binding Dic[foo]}
<Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:WpfApplication1 Title=Window1> <Grid> <local:ElementType x:Name=FirstElementName> <local:ElementType x:Name=SecondElementName Grid.Column=1 Grid.Row=1 />
Here's the XAML code: <Application x:Class=WpfApplication2.App xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Startup=Application_Startup /> Backing code: using System.Windows;
Why TextBlock remains black? <Window x:Class=WpfApplication4.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> <Style TargetType=TextBlock
In a wpf project I have this XAML code <Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
This is the code to reproduce this issue: xaml: <Window x:Class=WpfApplication1.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow

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.