32
A
回答
30
你忘了Background属性。画笔应该是一个ImageBrush,其ImageSource可以设置为图像路径。
<Grid>
<Grid.Background>
<ImageBrush ImageSource="/path/to/image.png" Stretch="UniformToFill"/>
</Grid.Background>
<...>
</Grid>
19
我有我的图像在一个单独的类库(“MyClassLibrary”),他们被放置在文件夹“图像”。在这个例子中,我使用“myImage.jpg”作为背景图片。
ImageBrush myBrush = new ImageBrush();
Image image = new Image();
image.Source = new BitmapImage(
new Uri(
"pack://application:,,,/MyClassLibrary;component/Images/myImage.jpg"));
myBrush.ImageSource = image.Source;
Grid grid = new Grid();
grid.Background = myBrush;
+0
自从你创建'Image'没有意义'不要用它来做任何事情。你可以直接在'ImageBrush'上设置'ImageSource'。 – devios1 2016-11-25 18:13:45
62
所有这一切都可以很容易地在XAML由网格
<Grid>
<Grid.Background>
<ImageBrush ImageSource="/MyProject;component/Images/bg.png"/>
</Grid.Background>
</Grid>
留给你做的,是添加一个文件夹来解决所谓的“形象”,并加入以下代码来达到的将现有文件添加到新的'Images'文件夹中,在这种情况下称为'bg.png'
0
为了避免路径问题,您可以简单地尝试此操作,只需在图像文件夹中保留背景图像并添加此代码
<Grid>
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="..\Images\background.jpg"
AlignmentY="Top" AlignmentX="Center"/>
</Grid.Background>
</Grid>
相关问题
- 1. 在WPF图像控件上设置背景图片?
- 2. 使用ImageBrush的网格背景图像
- 3. 如何在wpf中设置网格列的背景颜色?
- 4. 在LinearLayout上设置背景图像
- 5. J2ME在背景图像上设置textfield
- 6. 为iOS设置网站背景图像
- 7. 从Android上的图像设置背景
- 8. 在WPF中设置我的图像背景
- 9. 在WPF页面中添加网格背景图像
- 10. 使用BrowserAction设置背景图像
- 11. 使用Jekyll-Assets设置背景图像
- 12. 使用样式设置WPF控件背景图像?
- 13. 设置背景颜色和设置图像在ImageButton背景 - Android
- 14. 在WPF上设置背景颜色ContentView
- 15. WPF使用网格作为背景
- 16. 如何在wpf中设置动态窗口背景图像
- 17. 在UIViewController(MonoTouch)中设置背景图像
- 18. 在SD卡中设置背景图像
- 19. 在Java中设置背景图像
- 20. 在swift中设置navigationBar背景图像
- 21. 设置JWindow背景图像
- 22. 设置背景图像alertdialog
- 23. angularjs设置背景图像
- 24. 设置UIScrollView背景图像
- 25. UITableViewCell背景图像设置
- 26. 在网格视图中按项目位置设置背景
- 27. 如何在C#WPF代码中更改\设置按钮的背景图像?
- 28. 在背景图像上设置图像的问题android
- 29. 使用Swing在JFrame上设置背景图像
- 30. 如何使用Interface Builder在视图中设置背景图像
可以告诉我这个 – Shashank 2010-06-23 10:41:56
的确切语法@SHASHANK:语法是这样的:' ' –
Amsakanna
2010-06-23 10:49:19