2012-07-28 26 views
18

nasıl Grid içine Image nesne ekleme ve Sıra ve Sütun var ayarlayabilirsiniz ayarlamasına, bir ızgaraya bir çocuk ekler?o satır ve sütun

Kılavuz 3x3'tür.

Ana dosyası: dosyanın arkasında

<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="440" Width="400" ResizeMode="NoResize"> 
    <Window.Background> 
     <ImageBrush ImageSource="C:\Users\GuyD\AppData\Local\Temporary Projects\WpfApplication1\AppResources\Background.png"></ImageBrush> 
    </Window.Background> 
    <Grid ShowGridLines="True" x:Name="myGrid"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="42" /> 
      <RowDefinition Height="30*" /> 
      <RowDefinition Height="30*" /> 
      <RowDefinition Height="32*" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="31*" /> 
      <ColumnDefinition Width="26*" /> 
      <ColumnDefinition Width="32*" /> 
     </Grid.ColumnDefinitions> 
    </Grid> 
</Window> 

Kodu:

public MainWindow() 
{ 
    InitializeComponent(); 
    for (int i = 0; i < 3; i++) 
    { 
      for (int j = 0; j < 3; j++) 
      { 
       Image Box = new Image(); 
       this.myGrid.Children.Add(Box); 
      } 
    } 
} 
+0

daha iyi, soru size C# kodu kullanarak ızgaranın her bir hücrenin yüksekliğini ve genişliğini kontrol etmek istiyorsunuz anlamak için? –

+0

Bir alt öğe eklemek ve onun satır ve sütununu ayarlamak istiyorum – Novak

cevap

42

için ayarlamak için aşağıdaki kullanabilirsiniz.
satır 1 sütunda 1 koyun için:

Image Box = new Image(); 
myGrid.Children.Add(Box); 
Grid.SetRow(Box, 1); 
Grid.SetColumn(Box, 1); 
6

Sen Izgara ayarlayıcı yöntemleri statik hiçbir UIElement

Grid.SetRow(Box, i); 
Grid.SetColumn(Box, j); 
1
for (int i = 0; i < 4; i++) 
     { 
     for (int j = 0; j < 3; j++) 
     { 
      Image Box = new Image(); 
      this.myGrid.Children.Add(Box); 
      Grid.SetRow(Box, i); 
      Grid.SetColumn(Box, j); 
     } 
    } 

Ve evet Izgara 3X3 boyutlarının 4x3 ait değildir. Umarım bu yardımcı olacak.

0

bu deneyin:

public MainWindow() { 
InitializeComponent(); 
for (int i = 0; i < 3; i++) 
{ 
     for (int j = 0; j < 3; j++) 
     { 
      Image Box = new Image(); 
      Grid.SetRow(Box, i); 
      Grid.SetColumn(Box, j); 
     } 
} 
} 
İlgili konular