مشاركة عبر


كيفية القيام بما يلي: مشاركة خصائص تغيير الحجم صواب بين الشبكات

يوضح هذا المثال كيفية مشاركة تغيير الحجم في بيانات الأعمدة والصفوف بين Grid عناصر الاحتفاظ تغيير الحجم متناسقة.

مثال

المثال التالي يقدم جهازي Grid عنصر كتابع عنصر من أصل DockPanel. خاصية IsSharedSizeScope المرفقة الخاصة بـGrid معرفة على الأصل DockPanel .

تعالج المثال خاصية القيم بواسطة استخدام جهازي Button عناصر; يمثل كل عنصر "واحد من المنطقية خاصية القيم. عند IsSharedSizeScope خاصية يتم تعيين القيمة إلى true ، كل عمود أو صف عضو SharedSizeGroup مشاركات تغيير الحجم المعلومات بغض النظر عن محتوى صف أو عمود.

    <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>

<TextBlock Margin="10" DockPanel.Dock="Top" Name="txt1"/>

تعالج التعليمات البرمجية الخلفية التالية الأساليب التي يرفعها أحداث زر Click. في المثال تتم كتابة استدعاءات الأسلوب إلى عناصر TextBlock التي تستخدم أساليب الحصول المرتبطة لإخراج قيم الخاصية الجديدة كسلاسل.

Private Sub setTrue(ByVal sender As Object, ByVal args As RoutedEventArgs)

    Grid.SetIsSharedSizeScope(dp1, True)
    txt1.Text = "IsSharedSizeScope Property is set to " + Grid.GetIsSharedSizeScope(dp1).ToString()
End Sub

Private Sub setFalse(ByVal sender As Object, ByVal args As RoutedEventArgs)

    Grid.SetIsSharedSizeScope(dp1, False)
    txt1.Text = "IsSharedSizeScope Property is set to " + Grid.GetIsSharedSizeScope(dp1).ToString()
End Sub
private void setTrue(object sender, System.Windows.RoutedEventArgs e)
{
    Grid.SetIsSharedSizeScope(dp1, true);
    txt1.Text = "IsSharedSizeScope Property is set to " + Grid.GetIsSharedSizeScope(dp1).ToString();
}

private void setFalse(object sender, System.Windows.RoutedEventArgs e)
{
    Grid.SetIsSharedSizeScope(dp1, false);
    txt1.Text = "IsSharedSizeScope Property is set to " + Grid.GetIsSharedSizeScope(dp1).ToString();
}

راجع أيضًا:

المرجع

Grid

IsSharedSizeScope

المبادئ

نظرة عامة على اللوحات