Reputation: 679
I'm currently using the following xaml to style the resizegrip of a window, but it seems to ignore the ismouseover trigger.
<Style x:Key="{x:Type ResizeGrip}" TargetType="{x:Type ResizeGrip}">
<Setter Property="MinWidth" Value="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>
<Setter Property="MinHeight" Value="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarHeightKey}}"/>
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ResizeGrip}">
<Grid Name="GripGrid" SnapsToDevicePixels="True" Background="{TemplateBinding Background}">
<Path Name="GripPath" Fill="Silver" HorizontalAlignment="Right" Margin="0,0,2,2" VerticalAlignment="Bottom" Data="M 8,0 L 10,0 L 10,2 L 8,2 Z M 4,4 L 6,4 L 6,6 L 4,6 Z M 8,4 L 10,4 L 10,6 L 8,6 Z M 0,8 L 2,8 L 2,10 L 0,10 Z M 4,8 L 6,8 L 6,10 L 4,10 Z M 8,8 L 10,8 L 10,10 L 8,10 Z"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="GripPath" Property="Fill" Value="Red"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
i simply want to change colors of the grip on mouseover/down. can anyone help out or at least point me to the correct direction?
thanks!
Upvotes: 1
Views: 498
Reputation: 679
in case anyone needs something like this, i'm posting what i did (though not exactly what i was hoping for in)
i practically gave up on setting up the ismouseover trigger for the window's resize grip. what i did was to drop a thumb control on my window and setting a custom style like this:
<Style x:Key="RzGripThumb" TargetType="{x:Type Thumb}">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Grid Name="GripGrid" SnapsToDevicePixels="True" Background="Transparent">
<Path Name="GripPath" Fill="Gray" HorizontalAlignment="Right" Margin="0,0,2,2" VerticalAlignment="Bottom" Data="F1M9,0L11,0 11,2 9,2 9,0z M9,9L11,9 11,11 9,11 9,9z M9,3L11,3 11,5 9,5 9,3z M9,6L11,6 11,8 9,8 9,6z M0,9L2,9 2,11 0,11 0,9z M3,9L5,9 5,11 3,11 3,9z M3,6L5,6 5,8 3,8 3,6z M6,9L8,9 8,11 6,11 6,9z M6,3L8,3 8,5 6,5 6,3z M6,6L8,6 8,8 6,8 6,6z"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="GripPath" Property="Fill" Value="White"/>
</Trigger>
<Trigger Property="IsMouseCaptured" Value="true">
<Setter TargetName="GripPath" Property="Fill" Value="Lime"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
*the ismouseover is to change the color on hover, the ismousecaptured to change it while pressed.
the thumb control should aligned right & bottom.
then i added the DragDelta eventhandler for the thumb containing this:
double xadjust = this.ActualWidth + e.HorizontalChange;
double yadjust = this.ActualHeight + e.VerticalChange;
if ((xadjust >= this.MinWidth) && (yadjust >= this.MinHeight))
{
this.Width = xadjust;
this.Height = yadjust;
}
Upvotes: 2
Reputation: 69979
From the ResizeGrip
Class page:
The
ResizeGrip
is defined as part of the visual tree of aWindow
.
Therefore, you need to alter the ControlTemplate
of the Window
to make your changes of the ResizeGrip
work. Set your Style
as a DynamicResource
for the ResizeGrip Style
in the Window ControlTemplate
.
Here is an example adapted from the Window Styles and Templates page on MSDN:
<Style x:Key="{x:Type Window}"
TargetType="{x:Type Window}">
<Setter Property="SnapsToDevicePixels"
Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Grid>
<Grid.Background>
<SolidColorBrush Color="{DynamicResource WindowColor}"/>
</Grid.Background>
<AdornerDecorator>
<ContentPresenter />
</AdornerDecorator>
<ResizeGrip x:Name="WindowResizeGrip"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Visibility="Collapsed"
IsTabStop="false" />
Style="{DynamicResource YourStyle}"
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ResizeMode"
Value="CanResizeWithGrip">
<Setter TargetName="WindowResizeGrip"
Property="Visibility"
Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
You could use a StaticResource
if you will not be making any further changes to the Style
.
Upvotes: 0