![](/img/trans.png)
[英]How do I insert an escape character(e.g. "\t") into a string as "\t", not literal tabs?
[英]How do I paint a primitive inside of e.g. Ellipse?
我有一个椭圆形,如图所示。 我需要在给定的Ellipse内绘制一个图元,如图所示。
XAML:
<Ellipse
Width="300"
Height="200"
Fill="Yellow"/>
图片:
更新:看到我有用户控制。 本质上,这是一个椭圆形的基础。 另外,在给定的Ellipse中必须有一些图元。 另外,我需要通过Bindings分别隐藏/公开那些基元。
主要问题是:只需尝试将UC放入MainWindow中,看看会发生什么。 基本体将离开它们的坐标。 另外,如果我增加/减小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>
您需要使用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>
之前:
后:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.