在图表中我有一个StartPoint
和EndPoint
。那些Points
在它们和矩形之间创建一条线。除了这条线,我希望矩形变成绿色,并在角落变得透明。两点之间的矩形对角线渐变画笔
当然,渐变应该保留调整大小的点。不知何故,我真的不知道如何做到这一点,它真的让我发疯。
感谢您的帮助。
编辑: 如果我使用@Sheridans解决方案,如果将这个样子:
在图表中我有一个StartPoint
和EndPoint
。那些Points
在它们和矩形之间创建一条线。除了这条线,我希望矩形变成绿色,并在角落变得透明。两点之间的矩形对角线渐变画笔
当然,渐变应该保留调整大小的点。不知何故,我真的不知道如何做到这一点,它真的让我发疯。
感谢您的帮助。
编辑: 如果我使用@Sheridans解决方案,如果将这个样子:
希望这会有所帮助。
我已经使用编辑了线条系列模板BlurBitmapEffect并且我用相同的点添加了一条多段线以便我们可以实现BlurBitmapEffect。
例如。
<Grid>
<Polyline Points="0 1 1 0" Stroke="#9FBD5F" StrokeThickness="200" Stretch="Fill">
<Polyline.BitmapEffect>
<BlurBitmapEffect Radius="100" KernelType="Box" />
</Polyline.BitmapEffect>
</Polyline>
<Polyline Points="0 1 1 0" Stroke="#2DB14D" StrokeThickness="5" Stretch="Fill"/>
</Grid>
XAML
<Window x:Class="WpfApplication8.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:visualizationToolkit="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:Primitives="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"
Title="Window1" Height="500" Width="500">
<Window.Resources>
<Style x:Key="LineSeriesStyle1" TargetType="{x:Type chartingToolkit:LineSeries}">
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type chartingToolkit:LineSeries}">
<Canvas x:Name="PlotArea">
<!--You can use linergradient or visulbrush to give color to polyline -->
<!--or you can use additional polylines to achieve this affect-->
<Polyline Fill="Transparent" StrokeThickness="200" Points="{TemplateBinding Points}">
<Polyline.Stroke>
<SolidColorBrush Color="#9FBD5F"></SolidColorBrush>
</Polyline.Stroke>
<Polyline.BitmapEffect>
<BlurBitmapEffect Radius="100" KernelType="Box" />
</Polyline.BitmapEffect>
</Polyline>
<Polyline x:Name="polynine" Points="{TemplateBinding Points}" StrokeThickness="5" Stroke="#2DB14D"/>
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<chartingToolkit:Chart x:Name="mcChart" >
<chartingToolkit:LineSeries DependentValuePath="Value" IsSelectionEnabled="True" IndependentValuePath="Key" ItemsSource="{Binding}" Style="{StaticResource LineSeriesStyle1}"/>
</chartingToolkit:Chart>
C#
public Window1()
{
InitializeComponent();
LoadColumnChartData();
}
private void LoadColumnChartData()
{
((LineSeries)mcChart.Series[0]).ItemsSource =
new KeyValuePair<string, int>[]{
new KeyValuePair<string,int>("Project Manager", 13),
new KeyValuePair<string,int>("CEO", 23),};
}
结果
更新在供LineSeries模板添加此。
<Polyline Fill="Transparent" StrokeThickness="200" Points="{TemplateBinding Points}">
<Polyline.Stroke>
<SolidColorBrush Color="#9FBD5F"></SolidColorBrush>
</Polyline.Stroke>
<Polyline.Effect>
<BlurEffect Radius="100" KernelType="Box" />
</Polyline.Effect>
</Polyline>
你好Heena,谢谢你的帮助。这是非常好的 - 我认为唯一有效的解决方案。不幸的是'BlurBitmapEffect'被弃用:http://msdn.microsoft.com/de-de/library/system.windows.media.effects.blurbitmapeffect(v=vs.110).aspx你有一个例子使用一个常规影响? – 2014-11-28 13:06:15
@JohannesWanzek是的,它也与Effect.please看到更新。 – 2014-11-28 13:13:11
谢谢,那就是我正在寻找的! – 2014-11-28 14:55:03
使用精确的坐标Point
·您不能定义LinearGradientBrush
。相反,我们在一个虚构的矩形中指定Point
s,通常尺寸介于0
和1
之间。从MSDN上的LinearGradientBrush
Class页面开始:
LinearGradientBrush使用线性渐变绘制区域。线性渐变定义沿线的渐变。线的端点由线性渐变的StartPoint和EndPoint属性定义。 LinearGradientBrush画笔沿着这条线绘制它的GradientStops。
默认线性渐变是对角线。在默认情况下,线性渐变的StartPoint为(0,0),该区域的左上角被绘制,EndPoint为(1,1),该区域的右下角被绘制。沿着对角线路径插入结果梯度中的颜色。
可以调整StartPoint
和EndPoint
属性,使梯度更适合你的目标的控制,但GradientStop
S的关系是这个样子:
<Rectangle>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Offset="0" Color="Transparent" />
<GradientStop Offset="0.5" Color="LightGreen" />
<GradientStop Offset="1" Color="Transparent" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
该代码会导致这样的事情:
感谢您的回答@sheridan,但如果您调整窗口的大小会发生什么? – 2014-11-21 12:54:36
渐变将随'StartPoint'和'EndPoint'属性值而不是Window维度移动。但是,这些属性是'DependencyProperty's,因此您应该能够将数据绑定到适当的值以使其工作。 – Sheridan 2014-11-21 13:18:02
是的,这就是问题:这是如何工作的?我的意思是我也可以自己做一个渐变刷。 – 2014-11-21 13:44:38
“当然,渐变应该保留调整大小的点。” =>为了澄清这一点,你可以告诉我们什么梯度目前看起来像调整大小?你能告诉我们你是如何计算渐变的? – 2014-11-21 14:09:47
我试图根据点(2785,70)等来计算它,但是这没有奏效。当我使用sheridans的例子时,它只有当我有一个方形时才有效......这当然是有道理的。 – 2014-11-21 14:16:55
您可以向我们展示调整大小时的外观样式,以便我们看到问题所在? – 2014-11-21 14:19:39