Bonjour.
Y a t'il une subtilité pour pouvoir utiliser un propriété (du style Foreground) dans la définition des gradientstops ?
Le code suivant ne léve pas d'erreur mais ne fonctionne pas (la couleur du Background "rouge" n'est pas prise en compte dans le dégradé) :
Pour autant, celui-ci fonctionne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 <Window x:Class="Window4" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window4" Height="300" Width="300"> <Grid> <Grid.Resources> <Style TargetType="Button"> <!--Set to true to not get any properties from the themes.--> <Setter Property="OverridesDefaultStyle" Value="True"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <Rectangle> <Rectangle.Fill> <LinearGradientBrush x:Name="rr" StartPoint="0.5,0" EndPoint="0.5,1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <LinearGradientBrush.GradientStops> <GradientStop Color="Black" Offset="0" /> <GradientStop Color="{TemplateBinding Background}" Offset="0.5" /> <GradientStop Color="DarkBlue" Offset="0.5" /> <GradientStop Color="LightBlue" Offset="1" /> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </Grid.Resources> <Button Margin="60,69,96,111" Name="Button1" Background="Red" Foreground="White">Button</Button> </Grid> </Window>
J'ai raté quelque chose ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 <Window x:Class="Window4" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window4" Height="300" Width="300"> <Grid> <Grid.Resources> <Style TargetType="Button"> <!--Set to true to not get any properties from the themes.--> <Setter Property="OverridesDefaultStyle" Value="True"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <Rectangle Fill="{TemplateBinding Background}"> </Rectangle> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </Grid.Resources> <Button Margin="60,69,96,111" Name="Button1" Background="Red" Foreground="White">Button</Button> </Grid> </Window>
Cdt.
Partager