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

  • Home
  • SEARCH
  • 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 606913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:18:17+00:00 2026-05-13T17:18:17+00:00

Well i have a custom control called Dialog to slim it down to the

  • 0

Well i have a custom control called Dialog to slim it down to the problem
Here is my vb.net code:

Public Class Dialog
    Inherits System.Windows.Controls.Control

#Region "DependencyProperties"

    Public Shared ReadOnly OkCommandProperty As DependencyProperty = _
                           DependencyProperty.Register("OkCommand", _
                           GetType(ICommand), GetType(Dialog), _
                           New FrameworkPropertyMetadata(Nothing))

    Private Shared ReadOnly YesCommandPropertyKey As DependencyPropertyKey = _
                            DependencyProperty.RegisterReadOnly("YesCommand", _
                            GetType(ICommand), GetType(Dialog), _
                            New FrameworkPropertyMetadata(Nothing))

    Public Shared ReadOnly YesCommandProperty As DependencyProperty = _
                           YesCommandPropertyKey.DependencyProperty

#End Region

    Public ReadOnly Property YesCommand() As ICommand
        Get
            Return CType(GetValue(ConfirmationDialog.YesCommandProperty), ICommand)
        End Get
    End Property



    Public Sub New()
        MyBase.New()
        SetValue(ConfirmationDialog.YesCommandPropertyKey, New RelayCommand(AddressOf Yes))
    End Sub


#Region "Commands"
    Public Property OkCommand() As ICommand
        Get
            Return CType(GetValue(OkCommandProperty), ICommand)
        End Get
        Set(ByVal value As ICommand)
            SetValue(OkCommandProperty, value)
        End Set
    End Property
#End Region

#Region "Functions"
    Sub Ok()
        Dim command As ICommand = OkCommand
        If (command Is Nothing AndAlso command.CanExecute(Nothing)) Then
            command.Execute(Nothing)
        End If
    End Sub

    Sub Yes(ByVal parameter As Object)
        Ok()
        Me.Visibility = Windows.Visibility.Collapsed
    End Sub
#End Region

    Shared Sub New()
        'This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.
        'This style is defined in themes\generic.xaml
        DefaultStyleKeyProperty.OverrideMetadata(GetType(Dialog), New FrameworkPropertyMetadata(GetType(Dialog)))
    End Sub
End Class

and here is my xaml:

<Style TargetType="{x:Type local:Dialog}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:Dialog}">
               <Button Content="Yes" Command="{Binding YesCommand}"/> 
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

But YesCommand does not seem to work, but if i put OkCommand it works so why can’t i bind to a command thats defined and set in codebehind (or the control code)?

  • 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-05-13T17:18:17+00:00Added an answer on May 13, 2026 at 5:18 pm

    What is your DataContext? Do you need to set it:

    Public Sub New()
        MyBase.New()
        SetValue(ConfirmationDialog.YesCommandPropertyKey, New RelayCommand(AddressOf Yes))
        DataContext = Me
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed an asp.net control that inherits from the gridview and its called
I have a custom attribute: public class MenuItemAttribute : Attribute { } and a
I have written a few MSBuild custom tasks that work well and are use
I have a TemplateField that is dynamically added to a custom GridView. void ITemplate.InstantiateIn(System.Web.UI.Control
Well i have the custom flv player which reads an XmL and draws circles
Aloha, I have a custom control that I need to instantiate from within a
I have a custom user control UserProfileLink on which I have two basic string
Well I have made a custom Android UI, and I need my UI view
After I have changed my dll containing my custom control I am getting warnings
I have created a custom control which uploaded files to the server . These

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.