【问题标题】:Hide title bar on WPF User Control隐藏 WPF 用户控件上的标题栏
【发布时间】:2013-05-05 03:26:18
【问题描述】:

我正在寻找是否可以隐藏 WPF 用户控件窗口上的标题栏和关闭按钮。

我不能使用 WindowStyle="None",因为这仅与窗口有关,与用户控件无关。

有什么想法吗?

【问题讨论】:

    标签: wpf user-controls


    【解决方案1】:

    要关闭用户控件所在窗口的标题栏,可以在用户控件的代码中添加:

    // walk up the tree to get the parent window
    FrameworkElement parent = this.Parent;
    while(parent != null && !parent is Window)
    {
        parent = parent.Parent;
    }
    
    // if window found, set style
    if(parent != null && parent is Window)
    {
        parent.WindowStyle = WindowStyle.None;
    }
    

    【讨论】:

    • 工作就像一个魅力。干杯。
    猜你喜欢
    • 2016-04-26
    • 2013-10-21
    • 2021-11-04
    • 1970-01-01
    • 2012-12-13
    • 2018-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多