Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8560787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:21:25+00:00 2026-06-11T16:21:25+00:00

I am creating a custom UserControl and would like the UC to have a

  • 0

I am creating a custom UserControl and would like the UC to have a Command just like the Button. I am new to WPF.

This is what I have tried so far without any luck:

WelcomeView.xaml

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="150"/>
    </Grid.RowDefinitions>

    <Controls:SignedButton Grid.Row="1" VerticalAlignment="Top" Width="245" Height="45" Foreground="#FFFFFF" 
                           LeftSign="+" Text="Add an account" TextSize="20" 
                           ButtonBackground="#3A5795" HoverBackground="#C41AD7" HoverOpacity="1"
                           Command="{x:Static Infrastructure:ApplicationCommands.NavigateCommand}" 
                           CommandParameter="{x:Type Views:AddAccountView}"/>
</Grid>

SignedButton.xaml.cs

public partial class SignedButton : UserControl
{

    public static DependencyProperty ButtonBackgroundProperty =
        DependencyProperty.Register("ButtonBackground", typeof (string), typeof (SignedButton));

    public static DependencyProperty CommandParameterProperty =
        DependencyProperty.Register("CommandParameter", typeof (object), typeof (SignedButton));

    public static DependencyProperty CommandProperty =
        DependencyProperty.Register("Command", typeof (ICommand), typeof (SignedButton));

    public static DependencyProperty HoverBackgroundProperty =
        DependencyProperty.Register("HoverBackground", typeof (string), typeof (SignedButton));

    public static DependencyProperty HoverOpacityProperty =
        DependencyProperty.Register("HoverOpacity", typeof (double), typeof (SignedButton));

    public static DependencyProperty LeftSignProperty =
        DependencyProperty.Register("LeftSign", typeof (string), typeof (SignedButton));

    public static DependencyProperty RightSignProperty =
        DependencyProperty.Register("RightSign", typeof (string), typeof (SignedButton));

    public static DependencyProperty TextProperty =
        DependencyProperty.Register("Text", typeof (string), typeof (SignedButton));

    public static DependencyProperty TextSizeProperty =
        DependencyProperty.Register("TextSize", typeof (double), typeof (SignedButton));

    public SignedButton()
    {
        InitializeComponent();
    }

    public string ButtonBackground
    {
        get { return (string) GetValue(ButtonBackgroundProperty); }
        set { SetValue(ButtonBackgroundProperty, value); }
    }

    public ICommand Command
    {
        get { return (ICommand) GetValue(CommandProperty); }
        set { SetValue(CommandProperty, value); }
    }

    public object CommandParameter
    {
        get { return GetValue(CommandParameterProperty); }
        set { SetValue(CommandParameterProperty, value); }
    }

    public string HoverBackground
    {
        get { return (string) GetValue(HoverBackgroundProperty); }
        set { SetValue(HoverBackgroundProperty, value); }
    }

    public double HoverOpacity
    {
        get { return (double) GetValue(HoverOpacityProperty); }
        set { SetValue(HoverOpacityProperty, value); }
    }

    public string LeftSign
    {
        get { return (string) GetValue(LeftSignProperty); }
        set { SetValue(LeftSignProperty, value); }
    }

    public string RightSign
    {
        get { return (string) GetValue(RightSignProperty); }
        set { SetValue(RightSignProperty, value); }
    }

    public string Text
    {
        get { return (string) GetValue(TextProperty); }
        set { SetValue(TextProperty, value); }
    }

    public double TextSize
    {
        get { return (double) GetValue(TextSizeProperty); }
        set { SetValue(TextSizeProperty, value); }
    }
}

SignedButton.xaml

<UserControl x:Class="Client.Infrastructure.Controls.SignedButton"
             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="45" d:DesignWidth="245" 
             DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <UserControl.Resources>
        <FontFamily x:Key="OpenSans">. . .</FontFamily>
        <Storyboard x:Key="OnMouseEnter">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
                . . .
            </DoubleAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="grid">
                . . .
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="OnMouseLeave">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
                . . .
            </DoubleAnimationUsingKeyFrames>
            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="grid">
                . . .
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="Mouse.MouseEnter">
            . . .
        </EventTrigger>
        <EventTrigger RoutedEvent="Mouse.MouseLeave">
            . . .
        </EventTrigger>
    </UserControl.Triggers>
    <Grid x:Name="grid" Cursor="Hand" Background="{Binding ButtonBackground}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="50"/>
        </Grid.ColumnDefinitions>
        <TextBlock Text="{Binding LeftSign}" 
                   FontFamily="{DynamicResource OpenSans}" FontSize="{Binding TextSize}"
                   HorizontalAlignment="Center" VerticalAlignment="Center"/>
        <TextBlock Text="{Binding Text}" 
                   FontFamily="{DynamicResource OpenSans}" FontSize="{Binding TextSize}"
                   HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="1"/>
        <TextBlock Text="{Binding RightSign}" 
                   FontFamily="{DynamicResource OpenSans}" FontSize="{Binding TextSize}"
                   HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="2"/>
    </Grid>
</UserControl>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:21:26+00:00Added an answer on June 11, 2026 at 4:21 pm

    It looks like the one step you have left is to connect the ICommand interface to the UI of the control. Start by creating a mouse-click event listener.

    public SignedButton()
    {
        InitializeComponent();
        this.MouseUp += new MouseButtonEventHandler(MyClassContent_MouseUp);
    }
    
    void MyClassContent_MouseUp(object sender, MouseButtonEventArgs e)
    {
        Command.Execute(CommandParameter);
    }
    

    You’ll also want to listen to the CanExecuteChanged event on the Command instance, to enable/disable the clickable indicator on the UI.


    Footnote From the scope of the question, it might be advisable to extend the WPF Button control rather than re-invent its various features. It’s possible to customize its appearance and behavior in various ways, while still making use of core features like Visual States (pressed, active, disabled, etc) and the ICommand integration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a custom control derived from UserControl that I would like to set
I'm developing a WPF application, and I have created a custom usercontrol because I
I'm creating a Custom Usercontrol. It has two DependencyProperties I'd like to bind to
I am creating a user control and would like to create a custom menu
I'm creating custom control - image button. The purpose is to make button without
I'm creating custom UserControl in ASP.NET and I'm using System.ComponentModel.Attributes to decorate properties with
I'm looking for a tutorial that explains creating custom usercontrols in WPF. I want
I have mastered creating custom data types and adding fields with CCK. Then I
I am creating custom membership provider for my asp.net application. I have also created
I m creating custom checkbox and radio button in pure css but they are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.