标签: ismouseover

使用ShowDialog和无边框窗口时,IsMouseOver触发器不起作用

我有两个Windows申请.其中一个MainWindow是设置,另一个是设置.SettingsWindow当设置按钮被点击使用打开ShowDialog并设置其OwnerMainWindow.

SettingsWindow我窗口的最底部一个按钮,它的颜色变为红色时,IsMouseOverTrue蓝色False.但是当光标在MainWindow上时它不会改变.图像在下面是清楚的.我该如何解决这个问题?

CASE:光标不在SettingsWindow中,但它保持红色,没有变化.

在此输入图像描述

Xaml代码:

<Window x:Class="AltoSS.SettingsWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="SettingsWindow"
        Height="150"
        Width="360"
        WindowStyle="None"
        AllowsTransparency="True"
        WindowStartupLocation="CenterOwner">

  <!-- Other control codes-->
  <Button Grid.Row="2" Content="KAYDET" 
          FontSize="15"
          FontWeight="Bold"
          BorderBrush="Gray"
          BorderThickness="0,2,0,2">
    <Button.Style>
      <Style TargetType="Button">
        <Setter Property="Background" Value="Blue"/>
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="Button">
              <Border Background="{TemplateBinding Background}">
                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
              </Border>
              <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                  <Setter Property="Background" Value="Red"/>
                  <Setter Property="Foreground" Value="White"/>
                </Trigger>
              </ControlTemplate.Triggers> …
Run Code Online (Sandbox Code Playgroud)

wpf triggers ismouseover

9
推荐指数
1
解决办法
563
查看次数

WPF样式中IsMouseOver和IsHighlighted之间的区别

就像标题中一样,我想知道WPF样式中的IsMouseOverIsHighlighted属性触发器之间有什么区别。

有人知道吗?

wpf xaml triggers styles ismouseover

6
推荐指数
1
解决办法
778
查看次数

如何检查鼠标是否在控件上

如何检查鼠标是否在某个 HWND 上?我曾尝试使用 WM_MOUSELEAVE 和 WM_MOUSEMOVE 消息进行跟踪,但是如果您单击一个按钮并将鼠标拖出该按钮,则在释放鼠标之前它不会收到 WM_MOUSELEAVE,这为时已晚,因为:

当您单击一个按钮时,WM_COMMAND 消息仅在以下情况下发送:
1. 鼠标最初被压在按钮上
2. 鼠标在按钮上
3. 鼠标在按钮上释放

我需要复制这个功能。

c++ winapi controls ismouseover

5
推荐指数
1
解决办法
3754
查看次数

WPF触发器无法按预期工作

我想要一个红色按钮,当鼠标悬停在它上面时会变黑.

    <Button Content="Hover me" Grid.Column="3" Grid.Row="3">
        <Button.Style>
            <Style TargetType="{x:Type Button}">
                <Setter Property="Background" Value="Red"/>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="Black"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>
Run Code Online (Sandbox Code Playgroud)

但是,我的问题是,当我将鼠标悬停在按钮上时,它会变成具有渐变灰色外观的默认Windows样式.

wpf triggers styles button ismouseover

5
推荐指数
1
解决办法
5913
查看次数

在WPF中获取鼠标下的逻辑UIElement

似乎在Mouse下检索元素的所有方法都与Visual Hit测试有关.

是否有一些我缺少的机制可以让我抓住实际UIElement代表HitTest返回的当前可视树?

我正在做的总结:

我有一个自定义工具提示类,它依赖于基于鼠标结束的UIElement做的事情.

简单地说,它挂钩到拥有Window的PreviewMouseMove事件并更新"当前项目".此当前项应表示UIElement鼠标当前位于顶部.

不幸的是,我所遇到的一切Mouse.DirectlyOver,VisualTreeHelper.HitTest(包括回调)不起作用.

任何人都可以提供有关如何在Window MouseMove事件中的WPF中完成看似简单的任务的见解吗?

wpf mouse visualtreehelper event-bubbling ismouseover

4
推荐指数
1
解决办法
5940
查看次数

WPF - TabItem MouseOver未按预期工作

我有一个带有TabItem元素的IsMouveOver触发器的问题.

当鼠标光标位于TabItem上时,其背景颜色会发生变化,这就是我想要的=>它的工作原理.但是,只要我的鼠标光标位于TabItem内的项目上,TabItem的背景颜色也会发生变化.

这是与样式相关的XAML:

    <Style x:Key="SupTest" TargetType="{x:Type TabItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TabItem}">
                <Border Margin="2" Name="TabBorder" CornerRadius="6" BorderBrush="Transparent" Background="Transparent" 
                        BorderThickness="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                    <StackPanel Margin="12" Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <Rectangle Width="25" Height="25" Fill="Blue" HorizontalAlignment="Left" Margin="00,0,0,0"></Rectangle>
                        <ContentPresenter ContentSource="Header" VerticalAlignment="Center" 
                                          HorizontalAlignment="Stretch" Margin="10,0,0,0"></ContentPresenter>
                    </StackPanel>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Panel.ZIndex" Value="100" />
                        <Setter TargetName="TabBorder" Property="Background" Value="#FFDFDFDF" />
                        <Setter TargetName="TabBorder" Property="BorderThickness" Value="2" />
                        <Setter TargetName="TabBorder" Property="BorderBrush" Value="{DynamicResource WindowTitleColorBrush}"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="TabBorder" Property="Background" Value="DarkRed" />
                        <Setter TargetName="TabBorder" Property="BorderBrush" Value="Black" />
                        <Setter Property="Foreground" Value="DarkGray" …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml triggers ismouseover

3
推荐指数
2
解决办法
4493
查看次数

堆栈面板中的wpf鼠标悬停边距

我有一个标签项,标题具有以下形式:image_margin_textblock.

当鼠标光标在图像上方时,以及在文本块上方,触发器IsMouseOver正常工作.但是,当鼠标光标位于Image和Textblock之间的边距上时,不会触发IsMouseOver触发器.这会产生恼人的闪烁效果.

您是否有任何想法如何实现鼠标悬停触发?

这是代码:

<TabItem.Header>
<ContentControl>
    <ContentControl.Template>
        <ControlTemplate>
            <StackPanel x:Name="sp0" Orientation="Horizontal">
                <StackPanel x:Name="sp1" Orientation="Horizontal" Background="Blue">
                    <Image VerticalAlignment="Center" HorizontalAlignment="Center" Source="tab1.png"/>
                </StackPanel>
                <TextBlock Margin="10,0,0,0" Text="Tab1" VerticalAlignment="Center"/>
            </StackPanel>
            <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type TabItem}}}" Value="True">
                    <Setter TargetName="sp1" Property="StackPanel.Background" Value="Green"/>
                </DataTrigger>
                <Trigger SourceName="sp0" Property="IsMouseOver" Value="True">
                    <Setter TargetName="sp1" Property="StackPanel.Background" Value="Green"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </ContentControl.Template>
</ContentControl>
Run Code Online (Sandbox Code Playgroud)

谢谢.

wpf margin ismouseover

2
推荐指数
2
解决办法
1225
查看次数

IsMouseOver WPF 中的不透明度

我正在尝试更改 StackPanel 中某个项目的不透明度,但它似乎没有任何作用,我已经在网上搜索了大约一个小时,但似乎找不到我已经找到的内容做错了......这是我的代码:

<Window x:Class="Stations.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:m="clr-namespace:Stations.Model"
        xmlns:l="clr-namespace:Stations"
        Title="SpeedControl" WindowState="Maximized">
    <Window.Resources>
        <m:SpeedControl x:Key="MySpeedControl" />
        <m:NumberToMonthConverter x:Key="Converter" />
        <m:NumberToBrushConverter x:Key="BrushConverter" />
        <Style x:Key="Opacity1" TargetType="StackPanel">
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="StackPanel.Opacity" Value="1" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <ItemsControl Margin="10" ItemsSource="{Binding Source={StaticResource MySpeedControl}, Path=DataList}">
        <ItemsControl.Template>
            <ControlTemplate TargetType="ItemsControl">
                <Border BorderBrush="Aqua" BorderThickness="1" CornerRadius="15">
                    <ItemsPresenter/>
                </Border>
            </ControlTemplate>
        </ItemsControl.Template>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <DataTemplate.Resources>
                    <Style TargetType="TextBlock">
                        <Setter Property="FontSize" Value="12"/>
                        <Setter Property="HorizontalAlignment" Value="Center"/>
                    </Style>
                </DataTemplate.Resources>
                <Grid Background="Transparent">
                    <StackPanel Width="145px" Height="45px" Margin="4px" Opacity="{Binding Path=ViolationsRate}" …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml ismouseover

2
推荐指数
1
解决办法
3774
查看次数