- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个如下所示的 Xaml。我已经从表达式中的 emf 文件生成了 Xaml。我需要枚举和渲染 DrawingBrush 元素。我怎样才能做到这一点?谢谢!
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DrawingBrush x:Key="UnnamedObject0" Stretch="Uniform">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Geometry="F1 M 269.454,99.1347L 350.683,180.322L 395.356,135.671L 314.128,54.4843L 269.454,99.1347 Z ">
<GeometryDrawing.Pen>
<Pen Thickness="0.97367" StartLineCap="Round" EndLineCap="Round" LineJoin="Round" Brush="#FF000000"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
<DrawingBrush x:Key="UnnamedObject1" Stretch="Uniform">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="#FF000000" Geometry="F1 M 330.694,118.07L 330.694,118.008L 330.96,117.569L 331.351,117.19C 331.367,117.15 331.375,117.104 331.375,117.052C 331.375,116.961 331.35,116.891 331.3,116.841C 331.251,116.791 331.181,116.766 331.092,116.766C 331.031,116.766 330.973,116.78 330.917,116.807C 330.861,116.833 330.806,116.871 330.752,116.919L 330.752,116.816C 330.804,116.777 330.861,116.745 330.921,116.723C 330.981,116.7 331.044,116.688 331.11,116.688C 331.165,116.688 331.214,116.697 331.259,116.713L 331.373,116.783L 331.446,116.893C 331.463,116.936 331.472,116.984 331.472,117.037C 331.472,117.1 331.463,117.156 331.444,117.204C 331.426,117.252 331.401,117.296 331.37,117.336L 331.261,117.445C 331.219,117.478 331.175,117.511 331.128,117.544C 331.066,117.588 331.014,117.626 330.971,117.66L 330.809,117.859L 330.791,117.978L 330.791,117.992L 331.472,117.992L 331.472,118.07L 330.694,118.07 Z "/>
<GeometryDrawing Brush="#FF000000" Geometry="F1 M 332.114,116.688L 332.114,118.07L 332.017,118.07L 332.017,116.828C 331.973,116.87 331.924,116.907 331.868,116.938C 331.812,116.968 331.752,116.996 331.686,117.019L 332.083,116.688L 332.114,116.688 Z "/>
<GeometryDrawing Brush="#FF000000" Geometry="F1 M 332.425,118.018L 332.425,117.92C 332.529,117.981 332.626,118.011 332.718,118.011C 332.827,118.011 332.912,117.984 332.974,117.928C 333.036,117.873 333.067,117.801 333.067,117.711C 333.067,117.612 333.032,117.536 332.962,117.485C 332.892,117.434 332.793,117.408 332.664,117.408L 332.561,117.408L 332.561,117.331L 332.651,117.331C 332.767,117.331 332.856,117.304 332.917,117.252C 332.978,117.2 333.009,117.126 333.009,117.031C 333.009,116.949 332.986,116.884 332.941,116.837C 332.896,116.79 332.831,116.766 332.745,116.766C 332.661,116.766 332.574,116.797 332.483,116.858L 332.483,116.765C 332.584,116.714 332.677,116.688 332.761,116.688C 332.867,116.688 332.951,116.718 333.013,116.776C 333.075,116.835 333.106,116.912 333.106,117.009C 333.106,117.194 333.022,117.312 332.853,117.362L 332.853,117.366C 332.947,117.375 333.023,117.41 333.079,117.47C 333.136,117.53 333.164,117.606 333.164,117.698C 333.164,117.815 333.123,117.91 333.04,117.982C 332.957,118.053 332.85,118.089 332.718,118.089C 332.616,118.089 332.519,118.065 332.425,118.018 Z "/>
<GeometryDrawing Brush="#FF000000" Geometry="F1 M 333.495,118.054L 333.495,117.957C 333.568,117.993 333.635,118.011 333.695,118.011C 333.839,118.011 333.949,117.954 334.024,117.838C 334.099,117.723 334.137,117.553 334.137,117.328L 334.133,117.328C 334.07,117.472 333.958,117.544 333.796,117.544C 333.74,117.544 333.688,117.534 333.642,117.513L 333.522,117.428C 333.488,117.391 333.463,117.348 333.444,117.298C 333.426,117.247 333.417,117.192 333.417,117.132C 333.417,117.066 333.428,117.005 333.449,116.951C 333.469,116.897 333.498,116.85 333.536,116.811C 333.573,116.773 333.617,116.742 333.668,116.721C 333.719,116.699 333.775,116.688 333.835,116.688C 333.896,116.688 333.951,116.701 334,116.727C 334.05,116.752 334.092,116.791 334.126,116.842C 334.161,116.893 334.188,116.957 334.206,117.034C 334.225,117.11 334.234,117.199 334.234,117.302C 334.234,117.427 334.223,117.539 334.199,117.637C 334.176,117.734 334.142,117.817 334.096,117.884C 334.051,117.951 333.995,118.002 333.928,118.037C 333.861,118.072 333.783,118.089 333.695,118.089C 333.627,118.089 333.56,118.077 333.495,118.054 Z M 333.818,116.766L 333.6,116.865L 333.537,116.976C 333.522,117.019 333.514,117.065 333.514,117.114C 333.514,117.169 333.522,117.218 333.536,117.261L 333.693,117.442L 334.118,117.159C 334.118,117.102 334.11,117.05 334.095,117.001L 333.939,116.795L 333.818,116.766 Z "/>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</ResourceDictionary>
最佳答案
您可以使用 ItemsControl
并绑定(bind) ResourceDictionary
中的 DrawingBrush
列表
例子:
Xaml:
<Window x:Class="WpfApplication8.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Name="UI" Width="262" Height="318">
<Grid DataContext="{Binding ElementName=UI}">
<ItemsControl ItemsSource="{Binding Visuals}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Rectangle Width="200" Height="200" Fill="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Window>
代码:
namespace WpfApplication8
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
// Application Resources or any other ResourceDictionary
public IEnumerable<DrawingBrush> Visuals
{
get { return Application.Current.Resources.Values.OfType<DrawingBrush>(); }
}
}
}
结果:
如果您正在使用MergedDictionaries
,您可以使用
public IEnumerable<DrawingBrush> Visuals
{
get { return Application.Current.Resources.MergedDictionaries.SelectMany(r => r.Values.OfType<DrawingBrush>()); }
}
关于wpf - 如何在 WPF 中呈现 ResourceDictionary 中的 DrawingBrush 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18521378/
我需要在将放置其他控件的 Canvas 背景上绘制网格线。 我尝试创建一个 StreamGeometry,使用它来绘制线条,并将其分配给 DrawingBrush。但是我发现,如果 StreamGeo
我对 DrawingBrush 有以下定义。这是我在网上找到的一个画箭头的例子: 现在,我在 Canvas 上创建了一
假设我有一个 DrawingBrush,它具有硬编码的三种颜色,即边框、前景和背景。
我想画一个三角形作为边框背景。一种方法是使用 DrawingBrush,但在较小的尺寸下,抗锯齿会扭曲三角形并使其变得模糊。 如何禁用抗锯齿?
我正在尝试创建一个 50 x 50 的正方形,其中矩形的一半是白色,另一半是黑色(线条垂直而不是水平)。我有以下代码,但它没有按预期填充矩形。如何将其设为 50% 白色和 50% 黑色? System
我有一个带有矢量图形的 DrawingBrush。我想将其转换为 BitmapSource 作为将其转换为 Bitmap 的中间步骤。这样做的(最佳)方法是什么? 最佳答案 public static
我有一个如下所示的 Xaml。我已经从表达式中的 emf 文件生成了 Xaml。我需要枚举和渲染 DrawingBrush 元素。我怎样才能做到这一点?谢谢!
我用 C# 编写了一个基于 Windows Metro XAML 的应用程序,我想用我的自定义网格控件上的画笔绘制网格线。 在 WPF 中,我会创建一个 DrawingBrush来完成这项工作,但地铁
更新:这是因为我安装了 VS2012 RC。 (呃,抱歉应该说)。我有一个 WPF 切换按钮。我想在上面画图,所以做了一个Drawing Brush,我想控制画的颜色,所以绑定(bind)到Toggl
我是一名优秀的程序员,十分优秀!