- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望在XAML中使用ImageBrush
将背景应用于Grid
。
我给画笔指定了x:Key
,并希望在网格中引用它。
可悲的是,它根本没有将图像作为背景。
<Window.Resources>
<ImageBrush ImageSource="/MAQButtonTest;component/images/bird_text_bg.jpg" x:Key="BackgroundSponge" />
<Style TargetType="TextBlock">
<Setter Property="OverridesDefaultStyle" Value="True"/>
</Style>
<ControlTemplate TargetType="Button" x:Key="ButtonTemplate">
<Grid Width="444" ShowGridLines="False" SnapsToDevicePixels="True" Background="{DynamicResource BackgroundSponge}">
<Grid.RowDefinitions>
<RowDefinition Height="51" />
<RowDefinition Height="36" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="#286c97">
</Grid>
<Grid Grid.Row="1" Background="#5898c0">
<ContentPresenter Grid.Row="0" />
</Grid>
</Grid>
</ControlTemplate>
</Window.Resources>
DynamicResource
和
StaticResource
。
最佳答案
在主网格中,您拥有内部子元素,该子元素覆盖了外部网格的所有可用空间,这就是为什么您无法看到背景的原因。
<Grid Width="444"
Height="500"
Background="{DynamicResource BackgroundSponge}"
ShowGridLines="False"
SnapsToDevicePixels="True">
<Grid.RowDefinitions>
<RowDefinition Height="51" />
<RowDefinition Height="36" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="#286c97" Opacity="0.2" Margin="5"/>
<Grid Grid.Row="1" Background="#5898c0" Opacity="0.2" Margin="5">
<ContentPresenter Grid.Row="0" />
</Grid>
</Grid>
关于wpf - 使用ImageBrush的网格背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10721603/
我一直在尝试在我的应用页面上设置背景。 要做到这一点,很多人都说我需要使用 ImageBrush 对象。但是,当我尝试初始化以下代码行时出现错误: ImageBrush myBrush = new I
我正在使用图像处理 WPF。当调用 Image 控件来设置 imageSource 时,如果图像来自不同的线程而不是 GUI 线程,则需要使用调度程序。 我只是想知道我是否可以设置一个 ImageBr
我正在尝试将我的 WPF 窗口的背景设置为图像,但是当我尝试运行它时出现此异常: PresentationFramework.dll 中出现类型为“System.Windows.Markup.Xaml
我有一个带有背景图像的窗口。图像可能会在运行时发生变化,这对此并不重要。 我希望图像固定在左上角(确实如此)而不是缩放(这也是正确的)。但是当窗口大于图像时,我需要重复(平铺)图像。我是正在做...
我创建了一个已绘制的 Canvas 现在在我完成绘制后我想将它保存到文件 + 想在 C# 代码中将它转换为 pictureBox 或图像
我有以下 ImageBrush 声明,我想用它来绘制窗口的背景。 如果我使用 StaticResource 绑定(bind)到 Window 的 Background 属性来设置它,画笔会
我正在尝试在 Visual Studio 2013 中创建一个带有 ImageBrush 背景的非常简单的窗口,作为对更复杂项目的测试。图像显示在设计器中,但程序在我启动时崩溃了。这是 XAML:
我正在尝试添加一个图像作为 UserControl 的背景。根据变量的值,我需要更改该背景,但无论我使用什么路径或 Uri 格式,背景都不会改变。 我在 stackoverflow 中看到了很多问题,
我对 ImageBrush 有问题: 我想在用户调整窗口大小时重复图像。但是当前图像在用户调整窗口大
我有一个 Canvas ,我在上面绘制线条(通过线条或路径),为用户指明要遵循的道路。有没有办法改变这条线,让它显示重复的图像?我正在寻找的是有一个步骤图标(透明的 png)而不是一条直线。 谢谢!
有没有办法在 Silverlight(而不是图像)中的 ImageBrush 上放置剪切路径?我没有看到 Intellisense 提供它,但我想知道是否有办法做到这一点。 最佳答案 另一个不受欢迎的
我有一个 3D 平面,我正尝试使用 ImageBrush 渲染它,因为它是 DiffuseMaterial.Brush。如果我使用 SolidColorBrush,那么平面看起来很好,但无论是 Ima
我在尝试将图像绑定(bind)到 ImageSource 时遇到问题。我已经尝试了一些关于 stackoverflow 的其他修复,但没有一个有效。 我似乎在这一行中收到一条错误消息,指出集合“Ite
我尝试四处搜索,但找不到这个问题的答案:使用 ImageBrush 填充矩形而不是创建 BitmapImage 并设置其源属性是否有性能改进? 我必须渲染大量图像(我们正在尝试超过 5000 张),现
所以我尝试应用图像但看不到任何变化... 我错过了什么?谢谢!! BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource =
在 XAML 中: XAML 工作正常,但是如何在 C# 代码中创建上面的 ImageBrush: C#应该是这样的:
我有一个应用程序将屏幕截图发送到另一个需要在 WPF 窗口中显示它们的应用程序它工作得很好,除了唯一的问题,即每次我添加新背景时代码都会在内存中累积。 我该如何解决这个问题? 谢谢! privat
嘿,我有一个使用 silverlight API 的 Windows Phone 8.1 应用程序。我正在从我的 blob 存储中下载此图像。 该图像来自这样的链接:https://[service]
我需要在 Windows Phone 通用应用程序中创建一个圆形图像。 为了创建这种图像,我使用了这段代码: 但是这段代码对内存的影响很大,每张图片大
我的资源词典中有一个进度条控制模板。完整的代码是这样的:
我是一名优秀的程序员,十分优秀!