用WPF写代码还是Blend里画? Blend里怎么画呢? = = 求高手。。
解决方案 »
- .net User Control 用法
- 请问那里可以下载LowerCaseTokenizer,WhitespaceTokenizer
- 请帮解决:c#和wmi实现远程控制的安全权限问题
- 如何指定字符数读文件啊?
- 网站内存泄露,跪拜高手们来解决,谢谢大家,在线等
- 怎么样将用Exchange workflow designer设计的流程打包、发布?
- 求教datalist <ItemTemplate>里,在textbox的textchange事件里怎么得到此textbox所在项的索引
- 我想要在页面里面价格打印程序把页面打印出来怎么做
- 如何修改系统声音?(想去掉网页里点击时的声音)
- 一个关于远程对象传输地问题(高手进来看)
- wpf控件事件问题
- Winform在未激活的状态下执行事件
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
x:Class="WpfApplication12.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<Storyboard x:Key="Storyboard1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(ed:Arc.EndAngle)" Storyboard.TargetName="arc">
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="360"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
</EventTrigger>
</Window.Triggers> <Grid x:Name="LayoutRoot">
<Ellipse Fill="#FFF7F7F7" Margin="83,80,251,72" Stroke="Black"/>
<ed:Arc x:Name="arc" ArcThickness="1" ArcThicknessUnit="Percent" EndAngle="0" Fill="#FF8F1D1D" Margin="112,109,279,96" Stretch="None" Stroke="Black" StartAngle="0"/>
</Grid>
</Window>
偏偏用这么垃圾的blend。
看看 blend的代码写的一踏糊涂。
http://schemas.microsoft.com/expression/2010/drawing
不是吧
public class Pie : Shape {
protected override System.Windows.Media.Geometry DefiningGeometry {
get {
StreamGeometry geometry = new StreamGeometry();
geometry.FillRule = FillRule.EvenOdd; using (StreamGeometryContext context = geometry.Open()) {
DrawGeometry(context);
} geometry.Freeze();
return geometry;
}
} private void DrawGeometry(StreamGeometryContext context) {
var startPoint = new Point(CenterX, CenterY);
var endPoint = GetEndPoint();
context.BeginFigure(startPoint, true, true);
context.LineTo(new Point(CenterX, CenterY - Radius), true, true);
context.ArcTo(endPoint, new Size(Radius, Radius), 0, Angle > 180, SweepDirection.Clockwise, true, true);
} private Point GetEndPoint() {
Point result = new Point();
double a = Angle / 180.0f * Math.PI;
result.X = CenterX + Radius * Math.Sin(a);
result.Y = CenterY - Radius * Math.Cos(a);
return result;
} protected override void OnRender(DrawingContext dc) {
//dc.DrawRectangle(Brushes.Yellow, null, new Rect(RenderSize));
base.OnRender(dc);
} public double Radius {
get { return (double)GetValue(RadiusProperty); }
set { SetValue(RadiusProperty, value); }
} public static readonly DependencyProperty RadiusProperty =
DependencyProperty.Register("Radius", typeof(double), typeof(Pie), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
public double Angle {
get { return (double)GetValue(AngleProperty); }
set { SetValue(AngleProperty, value); }
} public static readonly DependencyProperty AngleProperty =
DependencyProperty.Register("Angle", typeof(double), typeof(Pie), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure)); public double CenterX {
get { return (double)GetValue(CenterXProperty); }
set { SetValue(CenterXProperty, value); }
} public static readonly DependencyProperty CenterXProperty =
DependencyProperty.Register("CenterX", typeof(double), typeof(Pie), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
public double CenterY {
get { return (double)GetValue(CenterYProperty); }
set { SetValue(CenterYProperty, value); }
} public static readonly DependencyProperty CenterYProperty =
DependencyProperty.Register("CenterY", typeof(double), typeof(Pie), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.AffectsMeasure));
}[code=XML]
<Window x:Class="Test21.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Test21"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Ellipse Width="100" Height="100" Stroke="Black" />
<local:Pie x:Name="pie" Angle="0" Fill="Yellow" HorizontalAlignment="Center" Width="100" Height="100" VerticalAlignment="Center" Stroke="Red" Radius="50" CenterX="50" CenterY="50" />
</Grid>
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="pie" Storyboard.TargetProperty="Angle" To="360" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
</Window>
[/code]
在VS要要添加引用的 Microsoft.Expression.Drawing
路径:C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.0\Libraries\Microsoft.Expression.Drawing.dll
public class Pie : Shape {
...
}
}把Pie放在Test12的名字空间下
那么在Xaml才能引用