WPF i Stylowanie kliknięcia

0

Witam,napisałem po jakimś czasie i kilku testach Customowy Przycisk na który nałożyłem kilka styli o których przeczytałem w internecie.Wszystko działa pięknie ale gdy się na niego kliknie to świeci się na niebiesko tak jak standardowe przyciski,chciałbym aby po kliknięciu nie było tego efektu,tylko zamiast niego jakiś inny jak np zmiana koloru całej kontrolki na kolor żółty.Wie ktoś jak to zrobić ?

Poniżej zamieszczam kod całego przycisku

CustomButton.xaml

 
<UserControl x:Class="RPad_2014_Ultimate.CustomButton"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" Name="btnCustom">
             
    <Button Click="Button_Click_1" Style="{StaticResource CustomButtonStyle}">
        <WrapPanel>
            <Image Source="{Binding ElementName=btnCustom, Path=ImageSource}"/>
            <TextBlock Text="{Binding ElementName=btnCustom, Path=Text}" />
        </WrapPanel>
    </Button>
</UserControl>

CustomButton.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RPad_2014_Ultimate
{
    /// <summary>
    /// Interaction logic for CustomButton.xaml
    /// </summary>
    public partial class CustomButton : UserControl
    {
        public CustomButton()
        {
            InitializeComponent();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            RaiseEvent(new RoutedEventArgs(ClickEvent));
        }
        public static readonly DependencyProperty TextProperty =
        DependencyProperty.Register("Text", typeof(String),
        typeof(CustomButton), new FrameworkPropertyMetadata(string.Empty));

        public String Text
        {
            get { return GetValue(TextProperty).ToString(); }
            set { SetValue(TextProperty, value); }
        }
        public static readonly DependencyProperty ImageSourceProperty =
        DependencyProperty.Register("ImageSource", typeof(ImageSource),
        typeof(CustomButton), new FrameworkPropertyMetadata(null));

        public ImageSource ImageSource
        {
            get { return GetValue(ImageSourceProperty) as ImageSource; }
            set { SetValue(ImageSourceProperty, value); }
        }
        public static readonly RoutedEvent ClickEvent =
    EventManager.RegisterRoutedEvent("Click", RoutingStrategy.Bubble,
    typeof(RoutedEventHandler), typeof(CustomButton));

        public event RoutedEventHandler Click
        {
            add { AddHandler(ClickEvent, value); }
            remove { RemoveHandler(ClickEvent, value); }
        }
    }
}

 

Theme.xaml

 
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="CustomButtonStyle" TargetType="Button">
        <Setter Property="BorderBrush" Value="Black" />
        <Setter Property="Background" Value="#FFF" />
        <Setter Property="Padding" Value="4" />
        <Style.Resources>
           
            <Style TargetType="TextBlock">
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
        </Style.Resources>
    </Style>
</ResourceDictionary>
1

Tutaj masz koncepcje wystarczy dostosować do swoich potrzeb.
http://stackoverflow.com/a/21704504

EDIT: Z całego postu ze stackoverflow po małych przeróbkach interesuje cię tylko tyle:

<Style TargetType="Button">
         <Setter Property="Template">
            <Setter.Value>
               <ControlTemplate TargetType="{x:Type Button}">
                  <Border Name="Border"
                        Background="{TemplateBinding Background}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        BorderBrush="{TemplateBinding BorderBrush}">
                     <ContentPresenter Name="Content"
                                      Content="{TemplateBinding Content}"
                                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                      TextBlock.FontFamily="{TemplateBinding FontFamily}"
                                      TextBlock.FontSize="{TemplateBinding FontSize}" />
                  </Border>
                  <ControlTemplate.Triggers>
                     <Trigger Property="IsPressed" Value="True">
                        <Setter  Property="Background" Value="Yellow" />
                     </Trigger>
                  </ControlTemplate.Triggers>
               </ControlTemplate>
            </Setter.Value>
         </Setter>
      </Style>
0

Ok,dodałem parę zdarzeń których potrzebuję i cały guziczek działa,bardzo dziękuje za pomoc

1 użytkowników online, w tym zalogowanych: 0, gości: 1