Use the IsSharedSizeScope attached property of the Grid element : Forms « Windows Presentation Foundation « C# / CSharp Tutorial






<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="WpfApplication1.Window1"
    Title="Grid IsSharedSizeScope Sample">
    <Border BorderBrush="Black" Background="White" BorderThickness="2">

  <DockPanel Name="dp1" Grid.IsSharedSizeScope="False" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10">
    <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">  
        <Button Click="setTrue" Margin="0,0,10,10">Set IsSharedSizeScope="True"</Button>
        <Button Click="setFalse" Margin="0,0,10,10">Set IsSharedSizeScope="False"</Button>
    </StackPanel> 

    <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
 
    <Grid ShowGridLines="True" Margin="0,0,10,0">
      <Grid.ColumnDefinitions>
        <ColumnDefinition SharedSizeGroup="FirstColumn"/>
        <ColumnDefinition SharedSizeGroup="SecondColumn"/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" SharedSizeGroup="FirstRow"/>
      </Grid.RowDefinitions>
        <Rectangle Fill="Silver" Grid.Column="0" Grid.Row="0" Width="200" Height="100"/>
        <Rectangle Fill="Blue" Grid.Column="1" Grid.Row="0" Width="150" Height="100"/>

        <TextBlock Grid.Column="0" Grid.Row="0" FontWeight="Bold">First Column</TextBlock>
        <TextBlock Grid.Column="1" Grid.Row="0" FontWeight="Bold">Second Column</TextBlock>
    </Grid>

    <Grid ShowGridLines="True">
      <Grid.ColumnDefinitions>
        <ColumnDefinition SharedSizeGroup="FirstColumn"/>
        <ColumnDefinition SharedSizeGroup="SecondColumn"/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>        
        <RowDefinition Height="Auto" SharedSizeGroup="FirstRow"/>
      </Grid.RowDefinitions>

        <Rectangle Fill="Silver" Grid.Column="0" Grid.Row="0"/>
        <Rectangle Fill="Blue" Grid.Column="1" Grid.Row="0"/>
 
        <TextBlock Grid.Column="0" Grid.Row="0" FontWeight="Bold">First Column</TextBlock>
        <TextBlock Grid.Column="1" Grid.Row="0" FontWeight="Bold">Second Column</TextBlock>
    </Grid>
    
    </StackPanel>

  </DockPanel>
  </Border>  
</Window>

//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;

namespace WpfApplication1
{
  public partial class Window1 : Window
  {
        public void setTrue(object sender, System.Windows.RoutedEventArgs e)
        {
            Grid.SetIsSharedSizeScope(dp1, true);
            Console.WriteLine(Grid.GetIsSharedSizeScope(dp1).ToString());
        }

        public void setFalse(object sender, System.Windows.RoutedEventArgs e)
        {
            Grid.SetIsSharedSizeScope(dp1, false);
            Console.WriteLine(Grid.GetIsSharedSizeScope(dp1).ToString());
        }
  }
}
WPF Use The Is Shared Size Scope Attached Property Of The Grid Element








24.74.Forms
24.74.1.Display a notification icon in the system tray.Display a notification icon in the system tray.
24.74.2.Add the PropertyGrid to the host, and the host to the WPF GridAdd the PropertyGrid to the host, and the host to the WPF Grid
24.74.3.Use the IsSharedSizeScope attached property of the Grid elementUse the IsSharedSizeScope attached property of the Grid element
24.74.4.Control the Size of UI Elements in a FormControl the Size of UI Elements in a Form
24.74.5.Define the Tab Order of UI Elements in a FormDefine the Tab Order of UI Elements in a Form