Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. IsMouseOver not sensed (Triggers in a Control Template) ???

IsMouseOver not sensed (Triggers in a Control Template) ???

Scheduled Pinned Locked Moved WCF and WF
questiondotnetwpfcomhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kb boxer
    wrote on last edited by
    #1

    I have defined a control template for a button, which would change the bacckgound color of the button when the mouse is over it. But sometimes the control does not sense the mouse is over it and the background color does not change. However, during such times, when the mouse is slowly moved over the content, the mouse is sensed and backgound changes. Please help me find what is wrong. (Try moving the mouse over the button either a bit fast or a bit slow).

    <Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
    x:Name="Window"
    Title="MainWindow"
    Width="640" Height="480">
    <Page.Resources> <Style x:Key="ButtonFocusVisual">
    <Setter Property="Control.Template">
    <Setter.Value>
    <ControlTemplate>
    <Rectangle Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="2" SnapsToDevicePixels="true"/>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    <LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
    <GradientStop Color="#F3F3F3" Offset="0"/>
    <GradientStop Color="#EBEBEB" Offset="0.5"/>
    <GradientStop Color="#DDDDDD" Offset="0.5"/>
    <GradientStop Color="#CDCDCD" Offset="1"/>
    </LinearGradientBrush>
    <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>
    <Style x:Key="EllipseButton" TargetType="{x:Type Button}">
    <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
    <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
    <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="Padding" Value="1"/>
    <Setter Property="Template">
    <Setter.Value>

    J 1 Reply Last reply
    0
    • K kb boxer

      I have defined a control template for a button, which would change the bacckgound color of the button when the mouse is over it. But sometimes the control does not sense the mouse is over it and the background color does not change. However, during such times, when the mouse is slowly moved over the content, the mouse is sensed and backgound changes. Please help me find what is wrong. (Try moving the mouse over the button either a bit fast or a bit slow).

      <Page
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
      x:Name="Window"
      Title="MainWindow"
      Width="640" Height="480">
      <Page.Resources> <Style x:Key="ButtonFocusVisual">
      <Setter Property="Control.Template">
      <Setter.Value>
      <ControlTemplate>
      <Rectangle Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="2" SnapsToDevicePixels="true"/>
      </ControlTemplate>
      </Setter.Value>
      </Setter>
      </Style>
      <LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
      <GradientStop Color="#F3F3F3" Offset="0"/>
      <GradientStop Color="#EBEBEB" Offset="0.5"/>
      <GradientStop Color="#DDDDDD" Offset="0.5"/>
      <GradientStop Color="#CDCDCD" Offset="1"/>
      </LinearGradientBrush>
      <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>
      <Style x:Key="EllipseButton" TargetType="{x:Type Button}">
      <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
      <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
      <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
      <Setter Property="BorderThickness" Value="1"/>
      <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
      <Setter Property="HorizontalContentAlignment" Value="Center"/>
      <Setter Property="VerticalContentAlignment" Value="Center"/>
      <Setter Property="Padding" Value="1"/>
      <Setter Property="Template">
      <Setter.Value>

      J Offline
      J Offline
      Jurgen Rohr
      wrote on last edited by
      #2

      Hi, you didn't set the Background property of the "Border" in your ControlTemplate thus leaving it "null". Hence there is nothing to 'sense' the mouseover. In fact, even if you move the mouse fats over the Button-content you get a reaction. So, either set it via TemplateBinding or at least set it to Transparent - anything but "null" will do. Cheers Jürgen

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups