Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I add a button to the WPF caption bar while using custom window chrome?
    primarykey
    data
    text
    <p>I'm attempting to create a simple button template in which the button normally looks like a single horizontal line, but when moused over, the button will display a "rectangle" color fill behind it. This is the code I have, but I can't seem to get the triggers to fire. </p> <pre><code>&lt;Window x:Class="TestStylingWPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;WindowChrome.WindowChrome&gt; &lt;WindowChrome CaptionHeight="36" GlassFrameThickness="0 0 0 1" ResizeBorderThickness="5" /&gt; &lt;/WindowChrome.WindowChrome&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="36" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Button Height="36" Width="36" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="0"&gt; &lt;Button.Template&gt; &lt;ControlTemplate&gt; &lt;Grid&gt; &lt;Rectangle x:Name="PART_ButtonBackgroundRectangle" Fill="LightGray" Width="36" Height="36" Opacity="0" /&gt; &lt;Path x:Name="PART_ButtonPath" Data="M10,26 L26,26" Stroke="DarkGray" StrokeThickness="1.5" /&gt; &lt;/Grid&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger SourceName="PART_ButtonBackgroundRectangle" Property="IsMouseOver" Value="True"&gt; &lt;Setter TargetName="PART_ButtonBackgroundRectangle" Property="Opacity" Value="1" /&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Button.Template&gt; &lt;/Button&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>Does anyone know why my trigger won't work, or perhaps a better way to do this? I'm sort of new to WPF and would like to refactor this out (so as to use it in many buttons), but am unsure how.</p> <p><strong>Update:</strong> Ok, so I guess it appears to be because the button is within the caption bar of the window. Is there a good way around this? Maybe a way to set click/hover priority to the button?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload