Path 在Silverlight 2中动态确定路径
我在画布中有一个圆角边框,希望在画布中添加一个剪切区域,以便将我添加的任何内容剪切到边框中的区域。我知道我可以设置画布的Clip属性,但是由于画布和对象是动态调整大小的,而不是在XAML中指定大小,所以我不知道如何计算要使用的路径。是否有某种方法可以从UIElement(本例中的边界)派生PathGeometry?如果不是,最好的方法是什么?这是我正在使用的测试页面的XAMLPath 在Silverlight 2中动态确定路径,path,silverlight-2.0,clipping,pathgeometry,Path,Silverlight 2.0,Clipping,Pathgeometry,我在画布中有一个圆角边框,希望在画布中添加一个剪切区域,以便将我添加的任何内容剪切到边框中的区域。我知道我可以设置画布的Clip属性,但是由于画布和对象是动态调整大小的,而不是在XAML中指定大小,所以我不知道如何计算要使用的路径。是否有某种方法可以从UIElement(本例中的边界)派生PathGeometry?如果不是,最好的方法是什么?这是我正在使用的测试页面的XAML <UserControl x:Class="TimelinePrototype.Page" xmlns="http
<UserControl x:Class="TimelinePrototype.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Margin="10">
<Button x:Name="cmdDraw" FontSize="18" Click="cmdDraw_Click" Content="Draw" Margin="0,0,5,0" VerticalAlignment="Bottom" />
<TextBlock x:Name="txtDateRange" FontSize="18" Margin="10,0,10,10" VerticalAlignment="Bottom" />
</StackPanel>
<Canvas x:Name="TimelineCanvas" Grid.Row="1" HorizontalAlignment="Stretch"
SizeChanged="TimelineCanvas_SizeChanged">
<Border x:Name="TimelineBorder"
Background="LightGray"
BorderBrush="Black"
BorderThickness="2"
CornerRadius="15"
Margin="10"
Grid.Row="1"
VerticalAlignment="Top">
</Border>
</Canvas>
</Grid>
尝试使用和属性
var height = TimelineCanvas.ActualHeight;
var width = TimelineCanvas.ActualWidth;
尝试使用和属性
var height = TimelineCanvas.ActualHeight;
var width = TimelineCanvas.ActualWidth;
我最终使用了这段代码,但仍然对其他方法感兴趣
RectangleGeometry clipRect = new RectangleGeometry();
clipRect.Rect = new Rect(TimelineBorder.Margin.Left, TimelineBorder.Margin.Top, TimelineCanvas.ActualWidth - (TimelineBorder.Margin.Left + TimelineBorder.Margin.Right), TimelineCanvas.ActualHeight - (TimelineBorder.Margin.Top + TimelineBorder.Margin.Bottom));
clipRect.RadiusX = TimelineBorder.CornerRadius.TopLeft;
clipRect.RadiusY = TimelineBorder.CornerRadius.TopLeft;
TimelineCanvas.Clip = clipRect;
我最终使用了这段代码,但仍然对其他方法感兴趣
RectangleGeometry clipRect = new RectangleGeometry();
clipRect.Rect = new Rect(TimelineBorder.Margin.Left, TimelineBorder.Margin.Top, TimelineCanvas.ActualWidth - (TimelineBorder.Margin.Left + TimelineBorder.Margin.Right), TimelineCanvas.ActualHeight - (TimelineBorder.Margin.Top + TimelineBorder.Margin.Bottom));
clipRect.RadiusX = TimelineBorder.CornerRadius.TopLeft;
clipRect.RadiusY = TimelineBorder.CornerRadius.TopLeft;
TimelineCanvas.Clip = clipRect;
试一试
blacklight工具包有一个圆角裁剪工具,是免费的。试试看
blacklight toolpack有一个圆角裁剪工具,是免费的。我曾想过使用这些工具,但不知道是否有其他更聪明的方法。我曾想过使用这些工具,但不知道是否有其他更聪明的方法。我必须认可这种方法;如果只是因为我已经用这种方法做了几十次,却没有看到更好的方法,我就不得不认可这种方法;如果只是因为我已经这样做了几十次,却没有看到更好的方法。