Gradient background button : Button « Windows Presentation Foundation « C# / C Sharp






Gradient background button

Gradient background button
      

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Nasty Button" Height="150" Width="550">
    <Grid Background="Black">
        <Button Margin="20" >
            <Button.Style>
                <Style TargetType="Button">
                    <Setter Property="Foreground">
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                <LinearGradientBrush.GradientStops>
                                    <GradientStop Offset="0.0" Color="Purple" />
                                    <GradientStop Offset="0.5" Color="Blue" />
                                    <GradientStop Offset="1.0" Color="Purple" />
                                </LinearGradientBrush.GradientStops>
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Button">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="50" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="50" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition MinHeight="50" />
                                    </Grid.RowDefinitions>
                     
                                    <Grid Grid.Column="1">
                                        <Rectangle RadiusX="10" RadiusY="10">
                                            <Rectangle.Fill>
                                                <RadialGradientBrush>
                                                    <RadialGradientBrush.GradientStops>
                                                        <GradientStop Offset="0.0" Color="Black" />
                                                        <GradientStop Offset="1.0" Color="Red" />
                                                    </RadialGradientBrush.GradientStops>
                                                </RadialGradientBrush>
                                            </Rectangle.Fill>
                                        </Rectangle>
                                        <ContentPresenter Margin="20,0,20,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                    </Grid>
                    
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Button.Style>
        </Button>
    </Grid>
</Window>

   
    
    
    
    
    
  








Related examples in the same category

1.Shaking ButtonShaking Button
2.Default ButtonDefault Button
3.Button with Image sourceButton with Image source
4.Button with OpacityMaskButton with OpacityMask
5.The button and text block are up-side down in the custom coordinate system.The button and text block are up-side down in the custom coordinate system.
6.TextBox as Button ContentTextBox as Button Content
7.Button IsMouseOverButton IsMouseOver
8.Using common TextElement attached properties
9.Button HorizontalAlignment="Center"Button HorizontalAlignment=
10.Fish Eye ButtonsFish Eye Buttons
11.Enlarge Button In XamlEnlarge Button In Xaml
12.Click to rotate a ButtonClick to rotate a Button
13.Click to scale a ButtonClick to scale a Button
14.Change Button Alignment, Margin, FontSize and Padding in Style SettingChange Button Alignment, Margin, FontSize and Padding in Style Setting
15.Gradient Button by RectangleGradient Button by Rectangle
16.Rotated 35 degreesRotated 35 degrees
17.Set VerticalAlignment/HorizontalAlignment for ButtonSet VerticalAlignment/HorizontalAlignment for Button
18.Button with Inline Property TriggerButton with Inline Property Trigger
19.The implementation of our button's Click event handler in XamlThe implementation of our button's Click event handler in Xaml
20.To add a button control and a text block to the canvas
21.Button mouse down eventButton mouse down event
22.Button mouse down previewButton mouse down preview
23.Simple Custom ButtonSimple Custom Button
24.Custom Shaped ButtonCustom Shaped Button
25.Set Delay and Interval for RepeatButtonSet Delay and Interval for RepeatButton
26.A simple template for a round buttonA simple template for a round button
27.Load style defined in Xaml and apply to the ButtonLoad style defined in Xaml and apply to the Button
28.Nested Button contentNested Button content
29.Button PreviewMouseLeftButtonDown action and MouseLeftButtonDown actionButton PreviewMouseLeftButtonDown action and MouseLeftButtonDown action
30.Button PreviewMouseDown action and MouseDown actionButton PreviewMouseDown action and MouseDown action
31.Button click actionButton click action
32.Dynamically add Button to a Grid and add Action listenerDynamically add Button to a Grid and add Action listener
33.Do event based on button nameDo event based on button name
34.Button Click event handlerButton Click event handler
35.Put Button onto a GridPut Button onto a Grid
36.Add buttons to a Canvas with codeAdd buttons to a Canvas with code