我有一个配置文件,开发人员可以通过传入一个字符串来指定文本颜色:
<text value="Hello, World" color="Red"/>
Run Code Online (Sandbox Code Playgroud)
而不是有一个巨大的开关语句寻找所有可能的颜色,只是使用类System.Drawing.Brushes中的属性而不是内部我可以这样说:
Brush color = Brushes.Black; // Default
// later on...
this.color = (Brush)Enum.Parse(typeof(Brush), prasedValue("color"));
Run Code Online (Sandbox Code Playgroud)
除了刷子/画笔中的值不是枚举.所以Enum.Parse没有给我带来快乐.建议?
我设法找到了如何制作WPF动画 - 两种颜色之间的过渡.
它被称为ColorAnimation并且效果很好.
ColorAnimation animation = new ColorAnimation
{
From = Colors.DarkGreen,
To = Colors.Transparent,
Duration = new Duration(TimeSpan.FromSeconds(1.5)),
AutoReverse = false
};
animation.Completed += new EventHandler(animation_Completed);
SolidColorBrush brush = new SolidColorBrush(Colors.Transparent);
animation.AccelerationRatio = 0.5;
Background = brush;
brush.BeginAnimation(SolidColorBrush.ColorProperty, animation);
Run Code Online (Sandbox Code Playgroud)
我正在使用它来动画我的usercontrol的背景.我的控件背景是SolidColorBrush.最近我改为LinearGradientBrush.现在我不能再使用我的动画了.
我需要动画从画笔到画笔,而不是颜色到颜色.和最好的选择是摘要刷型,它包括的SolidColor,的LinearGradient等,所以可从动画例如SolidColorBrush到LinearGradientBrush.这甚至可能吗?谢谢.
是否可以直接引用资源字典中另一个Brush的Brush值,而不使用Color定义(或者确切地说,将一个画笔资源复制到另一个画笔中)?
例如,我有一个Brush定义:
<SolidColorBrush x:Key="PanelBackgroundBrush" Color="White"/>
Run Code Online (Sandbox Code Playgroud)
我还有一些其他的画笔,我想和"PanelBackgroundBrush"完全相同,就像这样:
<SolidColorBrush x:Key="FolderColor" [BrushToCopy]="{StaticResource PanelBackgroundBrush}"/>
Run Code Online (Sandbox Code Playgroud)
因此"PanelBackgroundBrush"和"FolderColor"都使用白色.
我知道这可以通过使用常见的颜色定义以某种方式实现.
我怎样才能创建一个画笔,画出在水平轴和垂直轴上均匀分布的1个单位粗线的规则重复网格?想象一下方格纸,如果你愿意的话.
理想情况下,该解决方案将允许控制用于线条和背景的刷子(方块内的区域).通过这种方式,背景可以是透明的,因此网格可以用作叠加层.
编辑这是一张图片,显示了汤姆的答案结果如下:

对于此示例,使用网格来合成三个图层以显示网格是真正透明的.
我正在使用d3.js,我正在通过修改这个例子来处理拉丝区域图表.除了基于画笔的x轴变化之外,我还希望根据画笔中数据的y值重绘图表的y轴(类似于Google财经图表的行为) .
我已经使功能正常工作,但只是以能够在x和y空间中绘制画笔的方式.我通过首先在brush变量中添加ay比例来做到这一点:
var brush = d3.svg.brush()
.x(x2)
.y(y2)
.on("brush", brush);
Run Code Online (Sandbox Code Playgroud)
这使得brush.extent()返回以下多维数组:[ [x0, y0], [x1, y1] ].然后,我在brush()函数中使用此数据重新定义焦点图的x和y域:
function brush() {
var extent = brush.extent();
x.domain(brush.empty() ? x2.domain() : [ extent[0][0], extent[1][0] ]);
y.domain(brush.empty() ? y2.domain() : [ extent[0][1], extent[1][1] ]);
focus.select("path").attr("d", area);
focus.select(".x.axis").call(xAxis);
focus.select(".y.axis").call(yAxis);
}
Run Code Online (Sandbox Code Playgroud)
这是有效的,但是通过在画笔变量中定义y比例,用户现在可以在焦点图表中拖动"框",而不是像在原始图表中那样只能向西拖动.
基本上,我的问题是:如何获得属于画笔区域的值范围,而不是画笔区域本身的范围?这甚至可能吗?
d3的笔刷文档在这里.
我在哪里可以找到有关Brushes如何实现我自己的System.Windows.Media.Brush的足够信息?我可以处理所有可冻结的行李,但是为了让它起作用,我需要覆盖的并不是很明显.
是的,所以我并不是说我想使用预定义的画笔.我想扩展System.Windows.Media.Brush,这是一个抽象类.这完全是为了我自己的启发.我甚至不确定我能用什么样的刷子.我只是想了解刷子是如何工作的.如:
public AwesomeBrush : Brush
{
protected override Freezable CreateInstanceCore()
{
return new AwesomeBrush();
}
... // concrete brush stuff
}
Run Code Online (Sandbox Code Playgroud) 我创建了ac#windows应用程序并编写了75%的代码.该程序允许用户创建流程图,并根据状态对流程图形状进行着色.我希望它们成为像3d一样的按钮
来自网站Webdesign.org
我不想为每个按钮创建一个PNG,而是希望使用画笔或其他技术在C#中创建它们,例如:
// Create solid brush.
SolidBrush blueBrush = new SolidBrush(Color.Blue);
// Create points that define polygon.
PointF point1 = new PointF(50.0F, 50.0F);
PointF point2 = new PointF(100.0F, 25.0F);
PointF point3 = new PointF(200.0F, 5.0F);
PointF point4 = new PointF(250.0F, 50.0F);
PointF point5 = new PointF(300.0F, 100.0F);
PointF point6 = new PointF(350.0F, 200.0F);
PointF point7 = new PointF(250.0F, 250.0F);
PointF[] curvePoints = {point1, point2, point3, point4, point5, point6, point7};
// Define fill mode.
FillMode newFillMode = FillMode.Winding;
// …Run Code Online (Sandbox Code Playgroud) 如何为条纹创建画笔(DrawingBrush),如博客中所示:
http://blog.pixelingene.com/2008/09/quick-tip-to-get-a-striped-background/
我无法使用它,因为它使用了缩放变换,这意味着如果UI元素很小,条纹几乎不可见或太靠近.
我不能使用图像画笔,因为我需要绑定颜色.
我正在研究这个plnkr.我有三条线在角度30,45和60.我想在这些线上应用一个画笔,这样当图表被刷过时,线条会在它穿过拉丝矩形的地方重新绘制,并且轴上的值是适当的.非常感谢任何帮助或暗示解决这个问题.
编辑:如果您有不同的解决方案来绘制旋转的线条并刷在它们上面,它也受到欢迎.请帮忙.
var ga = d3.select("svg")
.append("g")
.attr("class", "a axis")
.attr("transform", "translate(" + margin.left + "," + (height + margin.top) + ")")
.selectAll("g")
.data([30, 45, 60])
.enter()
.append("g")
.attr("class", "rotatedlines")
.attr("transform", function(d) { return "rotate(" + -d + ")"; })
.attr("stroke-width", 1)
.attr("stroke", "black")
.attr("stroke-dasharray", "5,5");
Run Code Online (Sandbox Code Playgroud)
我认为标题很清楚!
我现在拥有的是:
System.Drawing.Color uiui = System.Drawing.ColorTranslator.FromHtml(myString);
var intColor = (uint)((uiui.A << 24) | (uiui.R << 16) | (uiui.G << 8) | (uiui.B << 0));
var bytes = BitConverter.GetBytes(uint.Parse(value));
var brush = new SolidColorBrush();
brush.Color = Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);
Run Code Online (Sandbox Code Playgroud)
1- myString就像我在标题中所说的那样#FFFFFF
2-这在BitConverter.GetBytes行上失败了,这让我感到惊讶,因为我得到了我的Color上的int表示!
3-无论如何,我知道COlor转换不是那么直观,但我觉得我做得不对......这是好方法吗?