画在WPF跨 [英] Draw a cross in WPF
本文介绍了画在WPF跨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个WPF控件。
我需要在后台一横,像这样:
I need to have in background a cross, like this:
在这之后,我能够在我的划线的背景添加其他控件:
After that, I'd be able to add other controls over my "crossed" background:
如何画十字,知道当我rezize控制,交叉应该遵循它的大小?
How should I draw the cross, knowing that when I rezize the control, the cross should follow its size?
推荐答案
快速和肮脏的方法是使用线路,将它们的坐标一些父容器的宽度和高度。事情是这样的:
Quick and dirty way is to use lines and bind their coordinates to the width and height of some parent container. Something like this:
<Grid Name="parent">
<Line X1="0" Y1="0" X2="{Binding ElementName='parent', Path='ActualWidth'}" Y2="{Binding ElementName='parent', Path='ActualHeight'}"
Stroke="Black" StrokeThickness="4" />
<Line X1="0" Y1="{Binding ElementName='parent', Path='ActualHeight'}" X2="{Binding ElementName='parent', Path='ActualWidth'}" Y2="0" Stroke="Black" StrokeThickness="4" />
</Grid>
使用网格作为母体指任何其他儿童添加到网格线之后将出现在线路的顶部
Using a grid as the parent means any other children added to the grid after the lines will appear on top of the lines:
<Grid Name="parent">
<Line X1="0" Y1="0" X2="{Binding ElementName='parent', Path='ActualWidth'}" Y2="{Binding ElementName='parent', Path='ActualHeight'}"
Stroke="Black" StrokeThickness="4" />
<Line X1="0" Y1="{Binding ElementName='parent', Path='ActualHeight'}" X2="{Binding ElementName='parent', Path='ActualWidth'}" Y2="0" Stroke="Black" StrokeThickness="4" />
<Label Background="Red" VerticalAlignment="Center" HorizontalAlignment="Center">My Label</Label>
</Grid>
这篇关于画在WPF跨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文