在fr-FR文化中将ArcSegment写入XPS文档时出错 [英] Error to write ArcSegment to an XPS document in fr-FR culture

查看:76
本文介绍了在fr-FR文化中将ArcSegment写入XPS文档时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写包含ArcSegment控件的图形时遇到一个奇怪的问题.

I meet one strange problem in writing a visual including ArcSegment control.

这是xaml代码:

       < Canvas x:Name ='canvas'保证金="20".宽度="300".身高="300">
           < Path Stroke =红色"; StrokeThickness ="3".填充=黄色">
                             < Path.Data>
                    < PathGeometry>
               b < PathFigure StartPoint ="113 113". IsClosed ="True">
              nbsp; bsp    < LineSegment Point ="113 0-1"; IsStroked =真". />
              nbsp; bsp    < ArcSegment x:Name ="arc"尺寸="113113" IsLargeArc ="True" SweepDirection =顺时针". RotationAngle ="340.5"
              nbsp; bsp             点="75.18 6.51"/
              nbsp; bsp    < LineSegment Point ="113113"; />
               b </PathFigure>
                    </PathGeometry>
                             </Path.Data>
           </Path>
           < Path Stroke =红色"; StrokeThickness ="3".填充=红色">
                             < Path.Data>
                    < PathGeometry>
               b < PathFigure StartPoint ="113 113". IsClosed ="True">
              nbsp; bsp    < LineSegment Point ="113 0-1"; />
              nbsp; bsp    < ArcSegment x:Name ="arc2"尺寸="113113" IsLargeArc ="False". SweepDirection =逆时针". RotationAngle ="19.5"
              nbsp; bsp             点="75.18 6.51"/
              nbsp; bsp    < LineSegment Point ="113 113"/<
               b </PathFigure>
                    </PathGeometry>
                             </Path.Data>
           </Path>
       </画布>

        <Canvas x:Name="canvas" Margin="20" Width="300" Height="300">
            <Path Stroke="Red" StrokeThickness="3" Fill="Yellow">
                <Path.Data>
                    <PathGeometry>
                        <PathFigure StartPoint="113 113" IsClosed="True">
                            <LineSegment Point="113 0" IsStroked="True" />
                            <ArcSegment x:Name="arc" Size="113 113" IsLargeArc="True" SweepDirection="Clockwise" RotationAngle="340.5"
                                        Point="75.18 6.51"/>
                            <LineSegment Point="113 113" />
                        </PathFigure>
                    </PathGeometry>
                </Path.Data>
            </Path>
            <Path Stroke="Red" StrokeThickness="3" Fill="Red">
                <Path.Data>
                    <PathGeometry>
                        <PathFigure StartPoint="113 113" IsClosed="True">
                            <LineSegment Point="113 0" />
                            <ArcSegment x:Name="arc2" Size="113 113" IsLargeArc="False" SweepDirection="Counterclockwise" RotationAngle="19.5"
                                        Point="75.18 6.51"/>
                            <LineSegment Point="113 113"/>
                        </PathFigure>
                    </PathGeometry>
                </Path.Data>
            </Path>
        </Canvas>

,这里是将该画布写入xps文档的代码:

and here the code to write this canvas to an xps document:

           //var cultureInfo = CultureInfo.GetCultureInfo("en-US");
           var cultureInfo = CultureInfo.GetCultureInfo("fr-FR");
           Thread.CurrentThread.CurrentCulture = cultureInfo;
           Thread.CurrentThread.CurrentUICulture = cultureInfo;

          字符串strXpsFile = $"C:\\ temp \\ {Guid.NewGuid().ToString()}.xps";

           var document = new XpsDocument(strXpsFile,FileAccess.ReadWrite);
           var xpsdw = XpsDocument.CreateXpsDocumentWriter(document);
           var vToXpsD = xpsdw.CreateVisualsCollat​​or();
           vToXpsD.Write(canvas);
           vToXpsD.EndBatchWrite();
           document.Close();

            //var cultureInfo = CultureInfo.GetCultureInfo("en-US");
            var cultureInfo = CultureInfo.GetCultureInfo("fr-FR");
            Thread.CurrentThread.CurrentCulture = cultureInfo;
            Thread.CurrentThread.CurrentUICulture = cultureInfo;

            string strXpsFile = $"C:\\temp\\{Guid.NewGuid().ToString()}.xps";

            var document = new XpsDocument(strXpsFile, FileAccess.ReadWrite);
            var xpsdw = XpsDocument.CreateXpsDocumentWriter(document);
            var vToXpsD = xpsdw.CreateVisualsCollator();
            vToXpsD.Write(canvas);
            vToXpsD.EndBatchWrite();
            document.Close();

我得到了一个损坏的XPS文档.

I get a broken xps document.

如果我将文化更改为en-US或InvariantCulture.或将RotationAngle设置为整数而不是十进制值,我可以获得正确的xps文档.似乎与小数点分隔符有关.

If I change the culture to en-US, or the InvariantCulture. or make the RotationAngle to an integer instead of a decimal value, I can get the correct xps document. Seems related to the decimal separator.

您对此有任何想法吗?

Do you have any idea about this?

推荐答案

>>您对此有任何想法吗?

是的,在几何"对象上调用ToString()方法时存在一个已知问题,这是当区域性"设置为"en-US"或类似区域性以外的其他内容时发生的事情.路径值应以逗号分隔 或空格,以便正确解析,但是在使用fr-FR文化时,ToString()方法返回分号分隔的值.请参阅以下页面以获取有关此信息的更多信息:

Yes, there is a known issue when calling the ToString() method on Geometry objects, which is what is happening under the hood here, when the Culture is set to something other than en-US or a similar culture. The Path values should be separated by a comma or a space in order to be parsed correctly but when using the fr-FR culture the ToString() method is returning semi-colon seperated values. Please refer to the following page for more information about this:

为什么将字符串路径转换为Geometry并再次返回会引发FormatException ?: http: //stackoverflow.com/questions/19464064/why-converting-a-string-path-to-geometry-and-back-again-throws-a-formatexception

Why converting a string path to Geometry and back again throws a FormatException?: http://stackoverflow.com/questions/19464064/why-converting-a-string-path-to-geometry-and-back-again-throws-a-formatexception

您可以在创建XPS文件之前将区域性临时设置为en-US或CultureInfo.Invariant,然后将Thread.CurrentThread.CurrentCulture设置为随后的原始区域性,从而轻松解决此问题:

You could easily work around this by temporarily setting the culture to en-US or CultureInfo.Invariant just before you create the XPS file and then set the Thread.CurrentThread.CurrentCulture back to your original culture immediately afterwards:

     string currentCulture = Thread.CurrentThread.CurrentCulture.Name;
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            string strXpsFile =


""C:\\ test \\ {Guid.NewGuid().ToString()}.xps"; var document = new XpsDocument(strXpsFile,FileAccess.ReadWrite); var xpsdw = XpsDocument.CreateXpsDocumentWriter(document); var vToXpsD = xpsdw.CreateVisualsCollat​​or(); vToXpsD.Write(画布); vToXpsD.EndBatchWrite(); document.Close(); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(currentCulture);
"C:\\test\\{Guid.NewGuid().ToString()}.xps"; var document = new XpsDocument(strXpsFile, FileAccess.ReadWrite); var xpsdw = XpsDocument.CreateXpsDocumentWriter(document); var vToXpsD = xpsdw.CreateVisualsCollator(); vToXpsD.Write(canvas); vToXpsD.EndBatchWrite(); document.Close(); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(currentCulture);

希望有帮助.

请记住,通过将有用的帖子标记为答案来关闭话题,然后在遇到新问题时开始新话题.请不要在同一线程中问几个问题.

Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


这篇关于在fr-FR文化中将ArcSegment写入XPS文档时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆