Silverlight - 史诗图形失败(由两个三角形矩形):( [英] Silverlight - Epic Graphical Fail (rectangle by two triangles) :(

查看:138
本文介绍了Silverlight - 史诗图形失败(由两个三角形矩形):(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用两个三角形绘制矩形。非常简单的任务。但Silverlight无法处理它。

 < Grid x:Name =LayoutRootUseLayoutRounding =FalseBackground =White> 
<多边形填充=黑色>
< Polygon.Points>
< Point X =10Y =100/>
< Point X =100Y =10/>
< Point X =100Y =100/>
< / Polygon>
<多边形填充=黑色>
< Polygon.Points>
< Point X =10Y =10/>
< Point X =100Y =10/>
< Point X =10Y =100/>
< / Polygon>

< / Grid>

逻辑上,当我编译这段代码时,我必须看到一个矩形。如果你尝试使用这段代码,你会看到矩形,但是你会有一条白色的线条。



所以我想知道..有没有在Silverlight中由两个三角形绘制矩形(看起来像矩形)的方法?

解决方案

这在Xaml中有点冗长,但是如果您以编程方式创建三角形,应该没关系,像这样:

 < Canvas Background =#FFF9B15AWidth =200Height =110VerticalAlignment =顶部Horizo​​ntalAlignment =左>> 
< Path Fill =BlackStrokeThickness =0>
< Path.Data>
< GeometryGroup>
< PathGeometry>
< PathGeometry.Figures>
< PathFigureCollection>
< PathFigure IsClosed =TrueStartPoint =10,10>
< PathFigure.Segments>
< PathSegmentCollection>
< LineSegment Point =100,10/>
< LineSegment Point =10,100/>
< / PathSegmentCollection>
< / PathFigure>
< / PathFigureCollection>
< /PathGeometry.Figures>
< / PathGeometry>
< PathGeometry>
< PathGeometry.Figures>
< PathFigureCollection>
< PathFigure.Segments>
< PathSegmentCollection>
< LineSegment Point =100,10/>
< LineSegment Point =100,100/>
< / PathSegmentCollection>
< / PathFigure>
< / PathFigureCollection>
< /PathGeometry.Figures>
< / PathGeometry>
< / GeometryGroup>
< /Path.Data>
< / Path>
< / Canvas>

通过这种方式,您可以合成具有三角形的单个元素Path。您显示的方式会创建单独的元素,并且每个元素都将单独进行反锯齿。



希望有帮助。



Sergio

I want to draw rectangle by two triangles. Very simple task. But Silverlight can't handle it.

<Grid x:Name="LayoutRoot" UseLayoutRounding="False" Background="White">
    <Polygon Fill="Black">
        <Polygon.Points>
            <Point X="10" Y="100"/>
            <Point X="100" Y="10"/>
            <Point X="100" Y="100"/>
        </Polygon.Points>
    </Polygon>
    <Polygon Fill="Black">
        <Polygon.Points>
            <Point X="10" Y="10"/>
            <Point X="100" Y="10"/>
            <Point X="10" Y="100"/>
        </Polygon.Points>
    </Polygon>

</Grid>

Logicly i have to see a rectangle when i compile this code. If you try to use this code you will see the rectangle but you will have an annoing white line in it...

So i whant to know.. is there a way to draw rectangle (that will look like rectangle) by two triangles in Silverlight?

解决方案

This is a little verbose in Xaml, but if you're creating the triangles programatically it shouldn't matter, how about something like this:

<Canvas Background="#FFF9B15A" Width="200" Height="110" VerticalAlignment="Top" HorizontalAlignment="Left">
    <Path Fill="Black" StrokeThickness="0">
        <Path.Data>
            <GeometryGroup>
                <PathGeometry>
                    <PathGeometry.Figures>
                        <PathFigureCollection>
                            <PathFigure IsClosed="True" StartPoint="10,10">
                                <PathFigure.Segments>
                                    <PathSegmentCollection>
                                        <LineSegment Point="100,10" />
                                        <LineSegment Point="10, 100" />
                                    </PathSegmentCollection>
                                </PathFigure.Segments>
                            </PathFigure>
                        </PathFigureCollection>
                    </PathGeometry.Figures>
                </PathGeometry>
                <PathGeometry>
                    <PathGeometry.Figures>
                        <PathFigureCollection>
                            <PathFigure IsClosed="True" StartPoint="10,100">
                                <PathFigure.Segments>
                                    <PathSegmentCollection>
                                        <LineSegment Point="100,10" />
                                        <LineSegment Point="100, 100" />
                                    </PathSegmentCollection>
                                </PathFigure.Segments>
                            </PathFigure>
                        </PathFigureCollection>
                    </PathGeometry.Figures>
                </PathGeometry>
            </GeometryGroup>
        </Path.Data>    
    </Path>
</Canvas>

This way you're really compositing a single element, the Path, with triangles. The way you've shown creates separate elements and each are going to be anti-aliased individually.

Hope that helps.

Sergio

这篇关于Silverlight - 史诗图形失败(由两个三角形矩形):(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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