具有相对尺寸的RectangleGeometry ...如何?

编程入门 行业动态 更新时间:2024-10-25 23:21:02
本文介绍了具有相对尺寸的RectangleGeometry ...如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在正在创建的按钮的控件模板上复制当今如此时尚的反射"效果.

I'm trying to replicate the nowadays so fashionable "reflex" effect on a controltemplate for buttons I'm creating.

基本思想是创建一个具有从白色到透明的渐变填充的矩形,然后使用矩形几何体裁剪该半透明的矩形.

The basic idea is to create a rectangle with a gradient fill from white to transparent and then clip some of that semi-transparent rectangle with a rectanglegeometry.

问题是我不知道如何定义相对的矩形几何形状.我通过定义一个较大的值(1000)来解决宽度问题,但是高度是一个问题.例如,它对于高度为200的按钮效果很好,但对于较小的按钮则无济于事.

The problem is that I don't know how to define a relative rectangle geometry. I kind of worked around width by defining a large value (1000), but height is a problem. For example, it works good for buttons that have a 200 height, but doesn't do anything for smaller buttons.

有什么想法吗?

<Rectangle RadiusX="5" RadiusY="5" StrokeThickness="1" Stroke="Transparent"> <Rectangle.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="0,0.55"> <GradientStop Color="#66ffffff" Offset="0.0" /> <GradientStop Color="Transparent" Offset="1.0" /> </LinearGradientBrush> </Rectangle.Fill> <Rectangle.Clip> <RectangleGeometry Rect="0,0,1000,60" /> </Rectangle.Clip> </Rectangle>

推荐答案

您可以使用MultiBinding和新的IMultiValueConverter:

public class RectangleConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { // you can pass in the value to divide by if you want return new Rect(0, 0, (double)values[0], (double)values[1] / 3.33); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotSupportedException(); } }

并在您的XAML中像这样使用:

And used like so in your XAML:

<lcl:RectangleConverter x:Key="rectConverter" /> ... <RectangleGeometry> <RectangleGeometry.Rect> <MultiBinding Converter="{StaticResource rectConverter}"> <Binding Path="ActualWidth" RelativeSource="{RelativeSource AncestorType={x:Type Button}}" /> <Binding Path="ActualHeight" RelativeSource="{RelativeSource AncestorType={x:Type Button}}" /> </MultiBinding> </RectangleGeometry.Rect> </RectangleGeometry>

更多推荐

具有相对尺寸的RectangleGeometry ...如何?

本文发布于:2023-11-12 01:12:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580087.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:尺寸   RectangleGeometry

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!