如何隐藏WPF控件的一部分 [英] How to hide a part of a WPF control

查看:215
本文介绍了如何隐藏WPF控件的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以隐藏WPF控件的一部分?根据 MSDN 。可以隐藏(在我的情况下)TextBox部分(可能命名为PART_TextBox)?

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 named PART_TextBox)?

我已经看到完全对DatePicker进行样式化的例子,它涉及到大量的XAML当我想要做的只是隐藏控件的一部分。

I have seen examples of styling the DatePicker completely, and it involves alot of XAML, when all I want to do is hide one part of the control.

推荐答案

嗯,我有一个解决你的案例: )

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;
        }
    }
}

这篇关于如何隐藏WPF控件的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆