WPF Grid怎么设置单元格的属性? 我是说Grid里自己用线分开的那些单元格?怎么控制啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 求救希望大侠能给我解决解决问题谢谢!http://topic.csdn.net/u/20101222/15/a4c712a0-01d1-4d25-87c2-48c65d9368c7.html 图片看不见<Grid ShowGridLines="True"> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid.Resources> <Style TargetType="TextBlock"> <Setter Property="FontSize" Value="14"/> <Setter Property="TextAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Center"/> </Style> </Grid.Resources> <TextBlock Grid.Row="0" Grid.Column="0" Text="0, 0"/> <TextBlock Grid.Row="0" Grid.Column="1" Text="0, 1"/> <TextBlock Grid.Row="0" Grid.Column="2" Text="0, 2"/> <TextBlock Grid.Row="1" Grid.Column="0" Text="1, 0"/> <Rectangle Grid.Row="1" Grid.Column="1" Fill="Green"/> <TextBlock Grid.Row="1" Grid.Column="1" Foreground="White"> 1, 1<LineBreak/> 中间的格子 </TextBlock> <TextBlock Grid.Row="1" Grid.Column="2" Text="1, 2"/> <TextBlock Grid.Row="2" Grid.Column="0" Text="2, 0"/> <TextBlock Grid.Row="2" Grid.Column="1" Text="2, 1"/> <TextBlock Grid.Row="2" Grid.Column="2" Text="2, 2"/></Grid> 楼主理解错误了,Grid 中的格子没有Background这个属性,不能设置的。需要在格子中加入控件,设置控件的属性。<Rectangle Name="rect1" Grid.Row="1" Grid.Column="1" Fill="Green"/>rect1.Fill = Brushes.Red;至于控件被放入哪个格子,是通过控件的 Grid.Row 和 Grid.Column 附加属性实现的。Grid.SetRow(rect1, 2); datagridview字体居中显示 C#能写LCD的驱动程序吗? 关于javascript转C# OOP具体指的是什么?? Windows服务安装问题 关于KeyDown 事件问题 求教:不规则窗体中的为什么会变透明? DataSet的用法(在线等) 不用visual studio,如何引用我用tlbimp生成的托管的excel的dll文件? C#中如何使一个线程暂停??? 求一段C#代码 sql 双重排序 翻页重复问题 在线等~~~
http://topic.csdn.net/u/20101222/15/a4c712a0-01d1-4d25-87c2-48c65d9368c7.html
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="14"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</Grid.Resources>
<TextBlock Grid.Row="0" Grid.Column="0" Text="0, 0"/>
<TextBlock Grid.Row="0" Grid.Column="1" Text="0, 1"/>
<TextBlock Grid.Row="0" Grid.Column="2" Text="0, 2"/> <TextBlock Grid.Row="1" Grid.Column="0" Text="1, 0"/>
<Rectangle Grid.Row="1" Grid.Column="1" Fill="Green"/>
<TextBlock Grid.Row="1" Grid.Column="1" Foreground="White">
1, 1<LineBreak/>
中间的格子
</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="2" Text="1, 2"/> <TextBlock Grid.Row="2" Grid.Column="0" Text="2, 0"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="2, 1"/>
<TextBlock Grid.Row="2" Grid.Column="2" Text="2, 2"/>
</Grid>
楼主理解错误了,Grid 中的格子没有Background这个属性,不能设置的。
需要在格子中加入控件,设置控件的属性。
<Rectangle Name="rect1" Grid.Row="1" Grid.Column="1" Fill="Green"/>
rect1.Fill = Brushes.Red;
至于控件被放入哪个格子,是通过控件的 Grid.Row 和 Grid.Column 附加属性实现的。Grid.SetRow(rect1, 2);