Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 具有相对尺寸的矩形几何体。。。怎样?_Wpf_Controls_Controltemplate_Clipping - Fatal编程技术网

Wpf 具有相对尺寸的矩形几何体。。。怎样?

Wpf 具有相对尺寸的矩形几何体。。。怎样?,wpf,controls,controltemplate,clipping,Wpf,Controls,Controltemplate,Clipping,我正在尝试在我正在创建的按钮的控制模板上复制当今如此流行的“反射”效果 基本思想是创建一个从白色到透明的渐变填充矩形,然后使用矩形几何体剪裁一些半透明矩形 问题是我不知道如何定义相对矩形几何体。我通过定义一个大值(1000)来解决宽度问题,但高度是个问题。例如,它适用于高度为200的按钮,但不适用于较小的按钮 有什么想法吗 <Rectangle RadiusX="5" RadiusY="5" StrokeThickness="1" Stroke="Transpare

我正在尝试在我正在创建的按钮的控制模板上复制当今如此流行的“反射”效果

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

问题是我不知道如何定义相对矩形几何体。我通过定义一个大值(1000)来解决宽度问题,但高度是个问题。例如,它适用于高度为200的按钮,但不适用于较小的按钮

有什么想法吗

            <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>

您可以使用一个
多绑定和一个新的
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中也是这样使用的:

<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>

...

它告诉我:'名称空间中不存在名称“MultiBinding”。'我不知道xaml名称空间的用途,但您的名称应该是
http://schemas.microsoft.com/winfx/2006/xaml/presentation
。我有:
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation“
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml“
。我的解决方案中没有一次出现“2007”。这是一个Windows Phone 8应用程序。这就是问题所在。Silverlight、WP7、WP8或WinRT中不存在多重绑定。如果你问我,这是一个相当大的疏忽,但你可以通过以下方式解决: