Click here to Skip to main content
15,567,448 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two Window for an application. One of them is MainWindow and the other is for settings. SettingsWindow is opened by using ShowDialog and setting its Owner to MainWindow when settings button is clicked.

On the `SettingsWindow` I have a button at the very bottom of the window and it changes the color to red when `IsMouseOver` is True and blue for False. But it doesn't change when the cursor is over the MainWindow. The image is below to be clear. How can I fix this problem?

CASE: The cursor is out of SettingsWindow but it keeps the red color, no change.

What I have tried:

<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 removed="{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>
                </ControlTemplate>
              </Setter.Value>
            </Setter>
          </Style>
        </Button.Style>
      </Button>
    </Window>


private void btnOpenSettings_Click(object sender, RoutedEventArgs e)
{
   SettingWindow sw = new SettingWindow();
   sw.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
   sw.Owner = this;
   sw.ShowDialog();
}
Posted
Updated 1-Sep-16 6:33am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900