Click here to Skip to main content
15,918,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
1. I want to create the properties like Command and Content of the user control's button which is used for another user control as buttons.
2. How to replace the image which is used inside button of a user control and is used for another user control's buttons.

In xaml: create a button as a user control containing a button which contains an image.

         <Style TargetType = "{x: Type Button}">
           <setter property = "Template">
                <controlTemplate TemplateType = "{x: Type Button}">
                   <ControlPresenter width= "{TemplateBinding Width}"/>
                    </controlTemplate >
             <Image source = ".jpg"  >

1 solution

Step : 1 - Create new command as a DepenedecyProperty and implement it 

Steo : 2 -  Bind Command property in the button the the MyButtonCommandProperty in your UserControl.

public Class YourUserControl: UserControl 

      public YourUserControl()
          MyButtonCommad = new RelayCommand
                         () => { // do some stuff in execute delegate},
                         () => { return true ;}                                                        

      public bool MyButtonCommad 
           get { return (ICommand)GetValue(MyButtonCommandProperty ); }
           set { SetValue(MyButtonCommandProperty , value); }

      public static readonly DependencyProperty MyButtonCommandProperty = 
                             DependencyProperty.Register("MyButtonCommad ", typeof(ICommand),new FrameworkPropertyMetadata(null));


// XAML : 

          <Button Command={Binding ElementName=control1,Path=MyButtonCommad ,Mode=OneWay/>
          <YourUserControl: x:Name="control1" />
Share this answer
Gautam Kesari B 1-Dec-13 1:52am    
There is no Command property in intelligence in xaml of the button created as an user control and used in another user control. I want to inherit that button from first user control and apply to second user control which behaves differently as more than on buttons. But i did not find the command property of the button in second user control. How to create the command property of the second user control's button ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900