8,757
社区成员
发帖
与我相关
我的任务
分享 <UserControl x:Class="Silverlight.GridLayout"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<UserControl.Resources>
<ImageBrush x:Key="bgBrush" ImageSource="Themes/images/1225414TH-3.jpg"/>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="Snow">
<StackPanel x:Name="dddd">
</StackPanel>
<Canvas x:Name="BGCanvas">
<Canvas.Resources>
<ImageBrush x:Key="imgBG" ImageSource="Themes/images/11324193B2-1.jpg" />
</Canvas.Resources>
</Canvas>
<Path x:Name="pathLine" Fill="White" Stretch="Fill" Margin="60,115,83,121" Data="M0.5,0.5 L87.951172,-88.749992 L118.26758,-39.749996 L199.5,0.5 L199.5,21.5 L117.49023,-18.749996 L88.728516,-67.749992 L0.5,21.5 z" UseLayoutRounding="False" StrokeThickness="20">
</Path>
</Grid>
</UserControl> pathLine.Stroke = this.Resources["bgBrush"] as ImageBrush; <Canvas x:Name="BGCanvas">
<Canvas.Resources>
<ImageBrush x:Key="imgBG" ImageSource="Themes/images/11324193B2-1.jpg" />
</Canvas.Resources>
</Canvas> /// <summary>
/// 为指定区域填充背景图
/// </summary>
/// <param name="canvasP">容器起点坐标</param>
/// <param name="cWidth">容器宽度</param>
/// <param name="cHeight">容器高度</param>
/// <param name="imgWidth">背景图宽度</param>
/// <param name="imgHeight">背景图高度</param>
void SetBGCanvas(Point canvasP,double cWidth,double cHeight,double imgWidth,double imgHeight)
{
Rectangle rect;
int x = (int)cWidth / (int)imgWidth + 1;
int y = (int)cHeight / (int)imgHeight + 1;
for (int i = 0; i < y; i++)
{
for (int j = 0; j < x; j++)
{
rect = new Rectangle();
rect.SetValue(Rectangle.WidthProperty,imgWidth);
rect.SetValue(Rectangle.HeightProperty,imgHeight);
rect.Fill = BGCanvas.Resources["imgBG"] as ImageBrush;
BGCanvas.Children.Add(rect);
Canvas.SetLeft(rect,canvasP.X + j * imgWidth);
Canvas.SetTop(rect, canvasP.Y + i * imgHeight);
}
}
}