Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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_Silverlight_Wpf Controls - Fatal编程技术网

创建空心边框/方形wpf

创建空心边框/方形wpf,wpf,silverlight,wpf-controls,Wpf,Silverlight,Wpf Controls,我想在WPF/Silverlight中创建一个控件。此控件为矩形/边框,从中心开始为空心。我的意图是灰显除矩形/边框容器中的正方形区域之外的所有其他区域。有可能这样做吗 此外,它应该能够移动鼠标移动这个空心区域 提前感谢大家的帮助 嗯,最简单的解决办法是: <Grid Width="256" Height="256" MouseMove="UIElement_OnMouseMove"> <Image Source="test1.jpg" Stretch="Uniform

我想在WPF/Silverlight中创建一个控件。此控件为矩形/边框,从中心开始为空心。我的意图是灰显除矩形/边框容器中的正方形区域之外的所有其他区域。有可能这样做吗

此外,它应该能够移动鼠标移动这个空心区域


提前感谢大家的帮助

嗯,最简单的解决办法是:

<Grid Width="256" Height="256" MouseMove="UIElement_OnMouseMove">
    <Image Source="test1.jpg" Stretch="UniformToFill" />
    <Path Fill="#81808080" Stretch="Fill">
        <Path.Data>
            <CombinedGeometry GeometryCombineMode="Exclude">
                <CombinedGeometry.Geometry1>
                    <RectangleGeometry Rect="0,0,100,100" />
                </CombinedGeometry.Geometry1>
                <CombinedGeometry.Geometry2>
                    <RectangleGeometry
                        x:Name="Hole"
                        RadiusX="7"
                        RadiusY="7"
                        Rect="20,20,60,60" /> <!-- this is the hole -->
                </CombinedGeometry.Geometry2>
            </CombinedGeometry>
        </Path.Data>
    </Path> 
</Grid>

hollow在这里指的是什么?嗨,David,我添加了一个示例图像以供参考。是的,这似乎与我尝试实现的相同,但问题是,当我想将Gemotery2的“Rect”属性数据绑定到鼠标移动时,似乎存在性能延迟。我的意思是运动不平稳。我已经创建了一个示例项目,下面给出了链接。我的目的是顺利地搬家。谢谢!代码的移动非常平滑。我仍然想知道为什么我的车很慢(如果我们转得更快的话)。
private void UIElement_OnMouseMove(object sender, MouseEventArgs e) {
    var element = (FrameworkElement) sender;
    var position = e.GetPosition(element);

    var relativeX = position.X/element.ActualWidth*100.0;
    var relativeY = position.Y/element.ActualHeight*100.0;

    Hole.Rect = new Rect(relativeX - 20, relativeY - 20, 40, 40);    
}