简体   繁体   English

如何在例如Ellipse中绘制基本体?

[英]How do I paint a primitive inside of e.g. Ellipse?

I have an Ellipse is looking like as shown at the pic. 我有一个椭圆形,如图所示。 I need to paint a primitive inside of given Ellipse, something like it is shown. 我需要在给定的Ellipse内绘制一个图元,如图所示。

XAML: XAML:

<Ellipse
            Width="300"
            Height="200"
            Fill="Yellow"/>

Picture: 图片: 椭圆

Update: As it's seen I have User Control. 更新:看到我有用户控制。 Essentially it's an Ellipse in base. 本质上,这是一个椭圆形的基础。 Also there are some primitives which have to be located within given Ellipse. 另外,在给定的Ellipse中必须有一些图元。 Also I need to hide/expose those primitives separately via Bindings. 另外,我需要通过Bindings分别隐藏/公开那些基元。

The major issue is: just try to put UC into MainWindow to see what will happen. 主要问题是:只需尝试将UC放入MainWindow中,看看会发生什么。 The primitives just will go away from their coordinates. 基本体将离开它们的坐标。 Also if I encrease/decrease the size of UC itself, it won't scale by proper way. 另外,如果我增加/减小UC本身的大小,它将无法通过适当的方式进行扩展。

<UserControl
    x:Class="Painting_test.UC_Ellipse"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:Painting_test"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DesignHeight="300"
    d:DesignWidth="300"
    mc:Ignorable="d">
    <Grid>


        <Ellipse
            Width="200"
            Height="200"
            Fill="Yellow"
            Stroke="Black" />
        <Path x:Name="Bridge"
            Width="34.5"
            Height="69.5"
            Margin="115.5,127,0,0"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            Data="M149,127 L115.5,195.5"
            Fill=" Yellow"
            Stretch="Fill"
            Stroke="Black" />
        <Path x:Name="Nose"
            Width="38.5"
            Height="1.008"
            Margin="115.5,195.5,0,0"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            Data="M115.5,196.492 L153,196.5"
            Fill=" Yellow"
            Stretch="Fill"
            Stroke="Black" />
        <Rectangle x:Name="SquareEye"
            Width="24"
            Height="24"
            Margin="103.984,118,0,0"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            Fill="Yellow"
            Stroke="Black" />
        <Ellipse x:Name="CircleEye"
            Width="24"
            Height="24"
            Margin="169,118,0,0"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            Fill="Yellow"
            Stroke="Black" />

    </Grid>
</UserControl>

You need to use Canvas instead of Grid as a container, and you need to use Canvas Left/Top instead of Margin , like this: 您需要使用Canvas而不是Grid作为容器,并且需要使用Canvas Left / Top而不是Margin ,如下所示:

<Viewbox 
        Stretch="Uniform" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch">
    <Canvas Width="200" Height="200">
        <Ellipse
            Canvas.Left="0"
            Canvas.Top="0"
            Width="200"
            Height="200"
            Fill="Yellow"
            Stroke="Black" />
        <Path x:Name="Bridge"
              Width="34.5"
              Height="69.5"
              Canvas.Left="65.5"
              Canvas.Top="63"
              HorizontalAlignment="Left"
              VerticalAlignment="Top"
              Data="M149,127 L115.5,195.5"
              Fill=" Yellow"
              Stretch="Fill"
              Stroke="Black" />
        <Path x:Name="Nose"
              Width="38.5"
              Height="1.008"
              Canvas.Left="65.5"
              Canvas.Top="145.5"
              HorizontalAlignment="Left"
              VerticalAlignment="Top"
              Data="M115.5,196.492 L153,196.5"
              Fill=" Yellow"
              Stretch="Fill"
              Stroke="Black" />
        <Rectangle x:Name="SquareEye"
                   Width="24"
                   Height="24"
                   Canvas.Left="53.984"
                   Canvas.Top="68"
                   HorizontalAlignment="Left"
                   VerticalAlignment="Top"
                   Fill="Yellow"
                   Stroke="Black" />
        <Ellipse x:Name="CircleEye"
                 Width="24"
                 Height="24"
                 Canvas.Left="119"
                 Canvas.Top="68"
                 HorizontalAlignment="Left"
                 VerticalAlignment="Top"
                 Fill="Yellow"
                 Stroke="Black" />
    </Canvas>
</Viewbox>

Before: 之前:

在此处输入图片说明

After: 后:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将转义字符(例如“\\t”)作为“\\t”而不是文字制表符插入字符串中? - How do I insert an escape character(e.g. "\t") into a string as "\t", not literal tabs? 如何按返回类型(例如,通过反射或IL)过滤EF过程? - How do I filter EF procedures by return type (e.g. via reflection or IL)? 将ASN.1数据转换为公钥需要什么?例如我该如何确定OID? - What is needed to convert ASN.1 data to a Public Key? e.g. how do I determine the OID? 如何确定一个值与另一个值(例如街道缩写)是否几乎相似? - How do I determine if one value is almost like another value (e.g. street abbreviations)? 如何创建受运行时变量影响的自定义属性? (例如PrincipalPermissionAttribute) - How do I create a custom attribute which is affected by runtime variables? (e.g. PrincipalPermissionAttribute) 如何手动创建嵌套的POST参数? (例如,我在.Net中创建请求以联系Rails后端) - how do I manually create POST parameters that are nested? (e.g. I'm creating the request in .Net to contact a Rails backend) 当您获得小时的小数时,Timespan是什么意思。 例如43.02:10:00以及如何避免 - What does a Timespan mean when you get decimals in the hours. e.g. 43.02:10:00 and how do I avoid it 如何使用字段名称的无效字符来解析Json? 例如,使用Newtonsoft {{“文件/文件夹”:“ /Shared/Salesforce/asdf.txt”}? - How do I parse Json with an invalid character for a field name? e.g. { “file/folder”: “/Shared/Salesforce/asdf.txt” } with Newtonsoft? 如何在roslyn中删除语法树中的标记。 例如从属性中删除虚拟关键字令牌? - How do I remove token in syntax tree in roslyn. e.g. remove virtual keyword token from property? 如何将字节转换为char,例如1 - &gt;&#39;1&#39;? - How to convert a byte to a char, e.g. 1 -> '1'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM