C# 在xaml网格列中放置小部件
嗨,我把手机屏幕分成三行,第二行分成两列。我正在尝试将图像添加到第二行的第二列。虽然我在图像属性中指定了Grid.Row和Grid.Column,但它不起作用。请您指导我如何在不同的行和列中添加小部件 非常感谢你的帮助C# 在xaml网格列中放置小部件,c#,wpf,xaml,window,C#,Wpf,Xaml,Window,嗨,我把手机屏幕分成三行,第二行分成两列。我正在尝试将图像添加到第二行的第二列。虽然我在图像属性中指定了Grid.Row和Grid.Column,但它不起作用。请您指导我如何在不同的行和列中添加小部件 非常感谢你的帮助 <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> <RowDefinition/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</Grid>
<Image
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="100"
Height="100"
Grid.Row="0"
Source="Assets/b_placeholder.jpg"/>
<Image
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="100"
Height="100"
Grid.Row="2"
Source="Assets/b_placeholder.jpg"/>
<Image
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="100"
Height="100"
Grid.Row="1"
Grid.Column="1"
Source="Assets/b_placeholder.jpg"/>
</Grid>
不能仅在一行中定义列 您可以在该行中创建一个仅包含列的新网格:
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Image
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="100"
Height="100"
Grid.Row="0"
Source="Assets/b_placeholder.jpg"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="100"
Height="100"
Grid.Column="1"
Source="Assets/b_placeholder.jpg"/>
</Grid>
<Image
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="100"
Height="100"
Grid.Row="2"
Source="Assets/b_placeholder.jpg"/>
</Grid>
或者在第一张和第三张图片上处理columnspan:
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="100"
Height="100"
Grid.Row="0"
Grid.ColumnSpan="2"
Source="Assets/b_placeholder.jpg"/>
<Image
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="100"
Height="100"
Grid.Row="1"
Grid.Column="1"
Source="Assets/b_placeholder.jpg"/>
<Image
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="100"
Height="100"
Grid.Row="2"
Grid.ColumnSpan="2"
Source="Assets/b_placeholder.jpg"/>
</Grid>
@Rao如果这回答了您的问题,您能将其标记为答案吗?谢谢