How to hide a part of a WPF control

前端 未结 4 1339
梦如初夏
梦如初夏 2021-02-02 03:30

Is it possible to hide a part of a WPF control? .NET 4 has a DatePicker which renders 4 parts, according to MSDN. Is it possible to hide (in my case) the TextBox part (probably

4条回答
  •  青春惊慌失措
    2021-02-02 04:10

    Well, I have a solution for your case :)

    class MyDateTimePicker : DatePicker
    {
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
    
            var textBox = this.Template.FindName("PART_TextBox", this) as UIElement;
            if (textBox != null)
            {
                textBox.Visibility = Visibility.Hidden;
            }
        }
    }
    

提交回复
热议问题