如何设置控件大小

gistop 2010-09-29 02:11:42
一grid A里面有一grid B

怎么设置,使B充满A(A的大小不确定)
...全文
123 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
勿说心想 2012-06-25
  • 打赏
  • 举报
回复
默认在Canvas或StackPanel中加入Image后,Image会根据外窗口的大小进行缩放



只要指定Image的Width或Height就可以使其显示原大小

可以用以下代码:

static UIElement CreateCanvas(BitmapSource bi)
{
var image = new Image {Source = bi, Width = bi.PixelWidth};
return image;
}
gistop 2010-09-29
  • 打赏
  • 举报
回复
下午怎么晕得厉害,学习silverlight时间也不短了怎么发现布局不会了

比如
<UserControl x:Class="test1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">

<Grid x:Name="LayoutRoot" Background="White">
<Grid x:Name="root" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel x:Name="children" Grid.Row="0" Grid.Column="0" Background="#FFE81212" AllowDrop="False" />
</Grid>
</Grid>
</UserControl>
这样的root是填充整个LayoutRoot的,children在第一列第一行中就是填充整个格子的,不用任何设置,在children下再放一grid的话
<UserControl x:Class="test1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">

<Grid x:Name="LayoutRoot" Background="White">
<Grid x:Name="root" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel x:Name="children" Grid.Row="0" Grid.Column="0" Background="#FFE81212" AllowDrop="False">
<Grid x:Name="childrengrid" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid>
</StackPanel>
</Grid>
</Grid>
</UserControl>
childrengrid就不填充整个children,只是width方向填充了
  • 打赏
  • 举报
回复
Grid没有Stretch属性
只有Image,ImageBrush,MediaElement,VideoBrush,Shape这些才有
ck436 2010-09-29
  • 打赏
  • 举报
回复
有一个strech还是什么的一个属性
  • 打赏
  • 举报
回复
你在页面一加载的时候就写上:
B.Width=A.ActualWidth;
B.Height=A.ActualHeight;
这样就可以填充满了
gistop 2010-09-29
  • 打赏
  • 举报
回复
grid中的RowDefinition这样的也可以用auto,但对于grid本身用auto不起作用
gistop 2010-09-29
  • 打赏
  • 举报
回复
不行啊,Height,Width为Auto后,grid就变Height,Width为0的样子了

StackPanel的这样可以

lzh4560 2010-09-29
  • 打赏
  • 举报
回复
使用Blend,填空Height,Width为Auto, 就搞定了

8,757

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧