I want to change the Forground color of a PivotItem Header when Mouse is Over with UWP,I work with windows 10
I tried this code:
<Page.Resources>
<SolidColorBrush x:Key="mouseOverColor"
Color="Red" />
</Page.Resources>
<Pivot HeaderTemplate="{StaticResource HeaderTemp}" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="10,0,10,0">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Narrow">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="Icon.(RelativePanel.AlignHorizontalCenterWithPanel)" Value="True" />
<Setter Target="LabelText.(RelativePanel.Below)" Value="Icon" />
<Setter Target="LabelText.(RelativePanel.AlignHorizontalCenterWith)" Value="Icon" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Wide">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="500" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="Icon.(RelativePanel.AlignVerticalCenterWithPanel)" Value="True" />
<Setter Target="LabelText.(RelativePanel.RightOf)" Value="Icon" />
<Setter Target="LabelText.(RelativePanel.AlignVerticalCenterWith)" Value="Icon" />
<Setter Target="RelativePanel.Margin" Value="0,0,12,0"/>
<Setter Target="Icon.Margin" Value="0,0,0,0"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Pivot.Resources>
<Style x:Key="myStyle" TargetType="PivotItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="PivotItem">
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background"
Value="{StaticResource mouseOverColor}" />
</Trigger>
</ControlTemplate.Triggers>
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Pivot.Resources>
<PivotItem Header="/images/img.png" Margin="12,10,12,0" >
<Grid>
.....
</Grid>
</PivotItem>
I have an error "The attachable property "Triggers" was not found in in type 'ControlTemplate' have you please any idea how can I change the color of an image when the mouse is over in a universal app thanks for help
You want to change the color of an image, I think it can not be done in the XAML designer, you can do it like this:
XAML code:
key code behind in .cs file:
To change the color of an image, you need to decode this image, get its
RGB
values, rewrite these values and turn them back to an image. And there is noForeground
property for anImage
control.