Hide the "editDropDownButton" of DateTimePicker

Editors for WPF Forum

Posted 5 years ago by Roger
Version: 13.2.0592
Avatar

Hi,

I'm trying to hide the "editDropDownButton" in the inherited class of DateTimePicker.
The following is the code snippet.

public class DateTimeControl : DateTimePicker {

    public DateTimeControl {
        this.Value = DateTime.Now;
        this.IsEditable = true;
        this.IsReadOnly = true;
    }
 
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        var element = (FrameworkElement)this.Template.FindName("editableDropDownButton", this);
        if (element != null) {
            element.Visibility = Visibility.Hidden;
        }
    }
}

On Windows7 environment, it works.

But on WindowsXPSP3(Japanese) environment, it does not work because

"this.Template.FindName(...)" returns null.

Could you please give me a clue for solving this problem?

 

Best Regards,

-- Tomonori Manome (and Shintaro "Roger" Iwamura)

Comments (2)

Answer - Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Roger,

The Default theme's template for the control isn't the same as the Aero theme's template.  Aero theme's template has the button with that name, but in the Default theme's template (which is used in XP), there is just a single "dropDownButton" that is used in both editable and non-editable mode.  You'd have to look for that as well if the other isn't found.

A side note though... instead of using this.Template.FindName, you should generally use this.GetTemplateChild.


Actipro Software Support

Posted 5 years ago by Roger
Avatar

Hi,

Thank you for your advice.  Exactly The "dropDownButton" is used in the default theme.

It solved the problem by finding both "editableDropDownButton" and  "dropDownButton".

 

By the way, 'GetTemplateChild' is obsolete, so I'm still using the 'Template.FindName'.

Kind Regards,

-- Tomonory Manome  (and  Shintaro "Roger" Iwamura)

The latest build of this product (v2019.1 build 0681) was released 19 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.