Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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_Wpf Controls_Wpf 4.0 - Fatal编程技术网

更改WPF上父网格鼠标的椭圆属性

更改WPF上父网格鼠标的椭圆属性,wpf,wpf-controls,wpf-4.0,Wpf,Wpf Controls,Wpf 4.0,我有一个网格,其中有一个椭圆,我希望鼠标在gid上,椭圆应该用红色填充。我怎么能做这件事?若我把触发器放在椭圆上,那个么它只在椭圆上的鼠标上。但是我希望颜色应该改变,因为鼠标在椭圆的父网格上 以下是我的用户控制代码: <UserControl x:Class="DeviceIcon" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://

我有一个网格,其中有一个椭圆,我希望鼠标在gid上,椭圆应该用红色填充。我怎么能做这件事?若我把触发器放在椭圆上,那个么它只在椭圆上的鼠标上。但是我希望颜色应该改变,因为鼠标在椭圆的父网格上

以下是我的用户控制代码:

    <UserControl x:Class="DeviceIcon"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="31" d:DesignWidth="31">


<Grid Background="#00000000" Name="MainGrid">
    <Ellipse Name="BackCircle" Width="30" Height="30" Fill="Lavender" Stroke="Red" >

    </Ellipse>
</Grid>


您可以将事件处理程序添加到父网格。鼠标事件从椭圆和其他子元素向上移动到网格

XAML

<Grid Background="#00000000"
      Name="MainGrid"
      MouseEnter='MainGrid_MouseEnter'
      MouseLeave='MainGrid_MouseLeave'>

    <Ellipse Name="BackCircle"
         Width="30"
         Height="30"
         Fill="Lavender"
         Stroke="Red">

    </Ellipse>
    </Grid>
   private Brush _oldFill;
   private void MainGrid_MouseEnter(object sender, MouseEventArgs e) {
      _oldFill = BackCircle.Fill;
      BackCircle.Fill = new SolidColorBrush(Colors.Red);
        }

    private void MainGrid_MouseLeave(object sender, MouseEventArgs e) {
      BackCircle.Fill = _oldFill;
     }