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

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Windows Presentation Foundation » Forms 
24.74.3.Use the IsSharedSizeScope attached property of the Grid element
<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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.