This project has moved and is read-only. For the latest updates, please go here.

DateTimePicker: Access internal Textbox

Oct 17, 2011 at 11:30 AM

Hey, how can I access the internal textbox of the DateTimePicker? I need to set its Context-Menü to Null. If I do this with the DateTimePicker I still get windows default context menu.

Oct 17, 2011 at 3:10 PM

Currently you will have to derive from the DateTimePicker control and override the OnApplyTemplate method.  In that method you can set TextBox.ContextMenu = null;

Oct 18, 2011 at 10:10 AM
Edited Oct 18, 2011 at 1:38 PM

Thank you. But unfortunately this doesn't work. I tried following 2 approaches:



public override void OnApplyTemplate(){
var t = this.GetTemplateChild("PART_EditableTextBox")as TextBox;
if(t != null)
{t.ContextMenu = null;}




 public override void OnApplyTemplate(){
if(this.TextBox != null)
{this.TextBox.ContextMenu = null;}


In both the TextBox is not recognized -> ContextMenu Property is not reached

Oct 18, 2011 at 2:44 PM

This is because :

  1. There is no PART_EditableTextBox in the template
  2. You didn't call base.OnApplyTemplate first.
    public override void OnApplyTemplate()
         TextBox.ContentMenu = null; //check for null


Oct 19, 2011 at 7:27 AM

My bad. Thanks a lot.  If I change ContentMenu to Contextmenu it works!!!