Click here to Skip to main content
15,887,683 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Opening new WPF form in seperate thread. Pin
SledgeHammer012-Feb-13 10:28
SledgeHammer012-Feb-13 10:28 
GeneralRe: Opening new WPF form in seperate thread. Pin
Hema Bairavan3-Feb-13 2:57
Hema Bairavan3-Feb-13 2:57 
GeneralRe: Opening new WPF form in seperate thread. Pin
SledgeHammer013-Feb-13 7:41
SledgeHammer013-Feb-13 7:41 
GeneralRe: Opening new WPF form in seperate thread. Pin
Jason Gleim1-Mar-13 8:00
professionalJason Gleim1-Mar-13 8:00 
QuestionHow to user control view open in center of main parent window ? Pin
rahul ameta2-Feb-13 1:56
rahul ameta2-Feb-13 1:56 
Questionarrange elements inside wpf Pin
Remix Mixdox1-Feb-13 22:27
Remix Mixdox1-Feb-13 22:27 
AnswerRe: arrange elements inside wpf Pin
Abhinav S3-Feb-13 7:02
Abhinav S3-Feb-13 7:02 
QuestionCustom Controls Pin
Sawyer19881-Feb-13 7:05
Sawyer19881-Feb-13 7:05 
Hi! Began studying wpf. Versed with custom control'ami. I create the control (simple button) from Control.
The question is - is it possible to not draw method OnRend (such as they call it), and make the template, the file generic.xaml? And still do not understand why does not my click handler.Confused | :confused:
C#
файл MyButton.cs
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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;
using System.Globalization;
 
namespace My_Lib
{  
    public class MyButton : Control
    {
        public static readonly RoutedEvent MyClickEvent;  
 
        static MyButton()
        {            
            DefaultStyleKeyProperty.OverrideMetadata(typeof(MyButton), new FrameworkPropertyMetadata(typeof(MyButton)));
                       
            MyClickEvent = EventManager.RegisterRoutedEvent("MyClick", RoutingStrategy.Bubble,
                typeof(RoutedEventHandler), typeof(MyButton));                       
        }
 
        public event RoutedEventHandler MyClick
        {
            add {
                base.AddHandler(MyButton.MyClickEvent, value);
            }
 
            remove {
                base.RemoveHandler(MyButton.MyClickEvent, value);
            }        
        }      
        
    }
}


XML
файл generic.xaml
 
 xmlns:local="clr-namespace:My_Lib">
 
 
    <LinearGradientBrush x:Key="Gray" 
    StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="PaleTurquoise" Offset="0" />
        <GradientStop Color="#CCCCFF" Offset="0.5" />
        <GradientStop Color="Teal" Offset="1" />
    </LinearGradientBrush>
 
 
    <LinearGradientBrush x:Key="Gray2" 
    StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="PaleGreen" Offset="0" />
        <GradientStop Color="#99CC99" Offset="0.5" />
        <GradientStop Color="Green" Offset="1" />
    </LinearGradientBrush>
 
 
    <Style TargetType="{x:Type local:MyButton}">
        <Setter Property="Width" Value="100"></Setter>
        <Setter Property="Height" Value="40"></Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:MyButton}">
                    <Border 
                        x:Name="ButtonBorder" 
                        Width="{TemplateBinding Width}"
                        Height="{TemplateBinding Height}"
                        BorderBrush="White"
                        CornerRadius="25" 
                        BorderThickness="2"
                        Background="{StaticResource Gray}"                        
                        Opacity="0.9"
                         >
                        <ContentPresenter x:Name="ButtonContentPresenter"
                                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                            Margin="{TemplateBinding Padding}" 
                                           >
                        </ContentPresenter>
                    </Border>
 
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver"  Value="True">
                            <Setter  TargetName="ButtonBorder"
                                     Property="Background"                                      
                                     Value="{StaticResource Gray2}">
                            </Setter>
                        </Trigger>                         
                    </ControlTemplate.Triggers>
                 </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>


C#
файл MainWindow.xaml.cs
 
namespace MyComponentsTest
{
 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
 
        private void myButton1_MyClick(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("sd");
        }         
    }
}  

QuestionApplication Launcher Pin
Mycroft Holmes31-Jan-13 13:49
professionalMycroft Holmes31-Jan-13 13:49 
AnswerRe: Application Launcher Pin
Abhinav S1-Feb-13 8:22
Abhinav S1-Feb-13 8:22 
QuestionWPF controls refresh Pin
caradri31-Jan-13 1:50
caradri31-Jan-13 1:50 
AnswerRe: WPF controls refresh Pin
Pete O'Hanlon31-Jan-13 2:44
mvePete O'Hanlon31-Jan-13 2:44 
GeneralRe: WPF controls refresh Pin
caradri31-Jan-13 10:20
caradri31-Jan-13 10:20 
GeneralRe: WPF controls refresh Pin
Richard Deeming31-Jan-13 11:25
mveRichard Deeming31-Jan-13 11:25 
GeneralRe: WPF controls refresh Pin
caradri2-Feb-13 17:59
caradri2-Feb-13 17:59 
GeneralRe: WPF controls refresh Pin
caradri3-Feb-13 20:16
caradri3-Feb-13 20:16 
QuestionRoutedEvent vs AttachedEvent Pin
devvvy29-Jan-13 22:30
devvvy29-Jan-13 22:30 
AnswerRe: RoutedEvent vs AttachedEvent Pin
Pete O'Hanlon29-Jan-13 22:51
mvePete O'Hanlon29-Jan-13 22:51 
GeneralRe: RoutedEvent vs AttachedEvent Pin
devvvy29-Jan-13 23:02
devvvy29-Jan-13 23:02 
GeneralRe: RoutedEvent vs AttachedEvent Pin
Pete O'Hanlon30-Jan-13 0:45
mvePete O'Hanlon30-Jan-13 0:45 
GeneralRe: RoutedEvent vs AttachedEvent Pin
devvvy30-Jan-13 2:40
devvvy30-Jan-13 2:40 
GeneralRe: RoutedEvent vs AttachedEvent Pin
Pete O'Hanlon30-Jan-13 2:44
mvePete O'Hanlon30-Jan-13 2:44 
GeneralRe: RoutedEvent vs AttachedEvent Pin
devvvy30-Jan-13 3:08
devvvy30-Jan-13 3:08 
QuestionWPF Tab Item Close Button Pin
Kevin Marois29-Jan-13 18:03
professionalKevin Marois29-Jan-13 18:03 
AnswerRe: WPF Tab Item Close Button Pin
SledgeHammer0129-Jan-13 19:02
SledgeHammer0129-Jan-13 19:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.