//创建Border
Border imageBorder = new Border(); imageBorder.Width = picWidth; imageBorder.Height = picWidth; //创建Grid Grid imageGrid = new Grid(); imageGrid.Width = imageBorder.Width; imageGrid.Height = imageBorder.Height; //设置Grid为Borde的子元素 imageBorder.Child = imageGrid;//创建图片Image image = new Image(); //设置图片资源 image.Source = new BitmapImage(new Uri(imageurl, UriKind.Relative)); //添加图片到Grid中 imageGrid.Children.Add(image);
ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = new BitmapImage(new Uri(imageurl, UriKind.Relative)); imageGrid.Background = imageBrush; image.Width = imageGrid.Width - 14; image.Height = imageGrid.Height - 14; descImage.Source = new BitmapImage(new Uri(imageurl, UriKind.Relative)); descImage.Width = imageGrid.Width; descImage.Height = 60; descImage.VerticalAlignment = VerticalAlignment.Bottom; //descImage.Margin = new Thickness(0,50,0,7); //添加说明图片到Grid中 imageGrid.Children.Add(descImage); RichTextBox priceText = new RichTextBox(); priceText.HorizontalAlignment = HorizontalAlignment.Left; priceText.VerticalAlignment = VerticalAlignment.Bottom; priceText.FontSize = 20; priceText.FontFamily = new FontFamily("Microsoft MHei Light"); priceText.Margin = new Thickness(2, 0, 0, 7.5); imageGrid.Children.Add(priceText); RichTextBox text = new RichTextBox(); text.HorizontalAlignment = HorizontalAlignment.Right; text.VerticalAlignment = VerticalAlignment.Bottom; text.FontSize = 20; text.Margin = new Thickness(2, 0, 0, 9); text.FontFamily = new FontFamily("Microsoft MHei Light"); imageGrid.Children.Add(text);