1
我有繪製箭頭的XAML,並且我嘗試將此XAML轉換爲代碼失敗: 上面的箭頭是XAML,下面的是代碼。從代碼中提取問題
有人能告訴我我在代碼中做了什麼錯誤嗎?我希望它看起來和XAML完全一樣。
XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle>
<Rectangle.Fill>
<DrawingBrush Stretch="Uniform">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Geometry="F1 M 3.64665,5.62366C 5.73362,3.09485 8.89196,1.48303 12.4268,1.48303C 16.1132,1.48303 19.3901,3.23596 21.4694,5.95398">
<GeometryDrawing.Pen>
<Pen Thickness="2.4" LineJoin="Round" Brush="Black"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Geometry="F1 M 21.4719,1.21204L 21.4719,5.96594L 16.7181,5.96594">
<GeometryDrawing.Pen>
<Pen Thickness="2.4" MiterLimit="2.75" Brush="Black"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Brush="Black" Geometry="F1 M 21.4593,0.00012207C 22.122,0.00012207 22.6593,0.537231 22.6593,1.20007C 22.6593,1.86267 22.122,2.40002 21.4593,2.40002C 20.7966,2.40002 20.2593,1.86267 20.2593,1.20007C 20.2593,0.537231 20.7966,0.00012207 21.4593,0.00012207 Z "/>
<GeometryDrawing Brush="Black" Geometry="F1 M 16.7121,4.76526C 17.3749,4.76526 17.9121,5.30261 17.9121,5.96545C 17.9121,6.62805 17.3749,7.16516 16.7121,7.16516C 16.0494,7.16516 15.5121,6.62805 15.5121,5.96545C 15.5121,5.30261 16.0494,4.76526 16.7121,4.76526 Z "/>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
<Image x:Name="img" Grid.Row="1"/>
</Grid>
後面的代碼:
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
img.Source = _createInnerIcon();
}
private DrawingImage _createInnerIcon()
{
SolidColorBrush lineBrush = Brushes.Black;
var dGroup = new DrawingGroup();
using (DrawingContext dc = dGroup.Open())
{
dc.DrawGeometry(lineBrush, new Pen(lineBrush, 2.4) { LineJoin = PenLineJoin.Round }, Geometry.Parse("F1 M 3.64665,5.62366C 5.73362,3.09485 8.89196,1.48303 12.4268,1.48303C 16.1132,1.48303 19.3901,3.23596 21.4694,5.95398"));
dc.DrawGeometry(lineBrush, new Pen(lineBrush, 2.4) { MiterLimit = 2.75 }, Geometry.Parse("F1 M 21.4719,1.21204L 21.4719,5.96594L 16.7181,5.96594"));
dc.DrawGeometry(lineBrush, new Pen(lineBrush, 1), Geometry.Parse("F1 M 21.4593,0.00012207C 22.122,0.00012207 22.6593,0.537231 22.6593,1.20007C 22.6593,1.86267 22.122,2.40002 21.4593,2.40002C 20.7966,2.40002 20.2593,1.86267 20.2593,1.20007C 20.2593,0.537231 20.7966,0.00012207 21.4593,0.00012207 Z "));
dc.DrawGeometry(lineBrush, new Pen(lineBrush, 1), Geometry.Parse("F1 M 16.7121,4.76526C 17.3749,4.76526 17.9121,5.30261 17.9121,5.96545C 17.9121,6.62805 17.3749,7.16516 16.7121,7.16516C 16.0494,7.16516 15.5121,6.62805 15.5121,5.96545C 15.5121,5.30261 16.0494,4.76526 16.7121,4.76526 Z "));
}
return new DrawingImage(dGroup);
}
}
還有的'的方式Brushes.Black'。 –
@ H.B - 是的,我知道,傻我..謝謝你! 如果你不介意,我已經修復了它的問題。 – Erez