追蹤如何以編程方式將路徑字符串轉換爲WPF中的路徑對象並不難,但有沒有內置函數可將幾何或路徑轉換回迷你語言中的字符串?將幾何/路徑轉換爲Minilanguage字符串?
5
A
回答
6
編輯︰看着這個剛纔我認爲應該有一個類GeometryConverter
應該能夠做到這一點,而且確實有。只需創建其中一個,然後在要轉換的幾何圖形上使用ConvertToString
即可。
可以使用XamlWriter
類輸出對象爲XAML,幾何會自動降低到小型語言。
例如如果這是你輸入:
<DrawingImage x:Name="segmentsDrawing">
<DrawingImage.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="Red">
<GeometryDrawing.Pen>
<Pen Brush="Black" />
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<PathGeometry>
<PathFigure StartPoint="100,100">
<PathFigure.Segments>
<LineSegment Point="100,0"/>
<ArcSegment Point="186.6,150" SweepDirection="Clockwise" Size="100,100"/>
<LineSegment Point="100,100"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="Blue">
<GeometryDrawing.Pen>
<Pen Brush="Black"/>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<PathGeometry>
<PathFigure StartPoint="100,100">
<PathFigure.Segments>
<LineSegment Point="186.6,150"/>
<ArcSegment Point="13.4,150" SweepDirection="Clockwise" Size="100,100"/>
<LineSegment Point="100,100"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="Green">
<GeometryDrawing.Pen>
<Pen Brush="Black"/>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<PathGeometry>
<PathFigure StartPoint="100,100">
<PathFigure.Segments>
<LineSegment Point="13.4,150"/>
<ArcSegment Point="100,0" SweepDirection="Clockwise" Size="100,100"/>
<LineSegment Point="100,100"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
...你序列化......
XmlTextWriter writer = new XmlTextWriter(@"C:\Users\Public\Test.xml", new UTF8Encoding());
writer.Formatting = Formatting.Indented;
writer.Indentation = 1;
writer.IndentChar = '\t';
XamlWriter.Save(segmentsDrawing, writer);
...你會得到如下:
<DrawingImage xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="#FFFF0000">
<GeometryDrawing.Pen>
<Pen Brush="#FF000000" />
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<PathGeometry Figures="M100,100L100,0A100,100,0,0,1,186.6,150L100,100" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="#FF0000FF">
<GeometryDrawing.Pen>
<Pen Brush="#FF000000" />
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<PathGeometry Figures="M100,100L186.6,150A100,100,0,0,1,13.4,150L100,100" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="#FF008000">
<GeometryDrawing.Pen>
<Pen Brush="#FF000000" />
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<PathGeometry Figures="M100,100L13.4,150A100,100,0,0,1,100,0L100,100" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
所有PathGeometry
現以微型語言。如果你想立即在你的應用程序中使用它,我想你可以把它寫入MemoryStream
,並通過它創建一個XmlDocument
來從中獲取數據。
+0
這是一個迂迴,但只是可能伎倆!謝謝... – 2011-04-16 23:07:33
相關問題
- 1. 將路徑轉換爲字符串?
- 2. 將查詢字符串轉換爲路由路徑
- 3. 如何將文件系統路徑轉換爲字符串
- 4. 如何將Unicode路徑轉換爲c字符串?
- 5. 如何將字符串轉換爲文件路徑(SD卡路徑)? android
- 6. 轉換文件路徑轉換爲字符串
- 7. 將字符串轉換爲運行命令VBScript的路徑
- 8. 將字符串路徑轉換爲輸入流
- 9. 獲取路徑,然後將其轉換爲字符串?
- 10. Nodejs將url字符串轉換爲只使用路徑名
- 11. 將文件路徑轉換爲字符串
- 12. 轉換字符串文件夾路徑
- 13. 可可路徑字符串轉換
- 14. 字符串資源路徑轉換器
- 15. 問題從轉換路徑字符串 「/」, 「\」
- 16. 如何將常規目錄路徑替換爲java路徑作爲字符串
- 17. 將字符串轉換爲字符串
- 18. 如何將路徑轉換轉換爲路徑中的ImageBrush?
- 19. c#將路徑轉換爲新路徑\\
- 20. 將HTTP路徑轉換爲UNC路徑?
- 21. 將'../../'轉換爲'路徑/路徑'
- 22. 將路徑轉換爲UNC路徑
- 23. 將字符串轉換爲
- 24. 將字符串轉換爲「_」
- 25. 將字符串轉換爲?
- 26. 如何將路徑轉換爲FFI的常量字符*?
- 27. 將URI轉換爲路徑
- 28. 將包含幾個數字的字符串轉換爲整數
- 29. 如何將字符串的字符串轉換爲字符?
- 30. asp.net mvc - 我如何將本地文件路徑字符串轉換爲http url
我想不是,因爲它是相反的方式:迷你語言被解析成幾何。 – 2011-03-08 19:13:43
「追蹤如何以編程方式將路徑字符串轉換爲WPF中的路徑對象並不困難」小心分享一些資源? – jpierson 2011-07-16 05:16:22
當然! http://stackoverflow.com/questions/2029680/wpf-c-path-how-to-get-from-a-string-with-path-data-to-geometry-in-code-not-in – 2011-07-22 14:32:11