如何在WPF中使用附加属性隐藏窗口TitleBar

时间:2018-04-10 09:50:09

标签: c# wpf xaml

在我的MainWindow中,我必须使用附加属性执行TitleBar隐藏或在ViewModel中可见。我不知道如何做到这一点。请任何人都可以给我一个建议或任何解决方法来实现这一目标。我是.Net的新手

public static readonly DependencyProperty TitleBarProperty = DependencyProperty.Register("TitleBarVisible", typeof(bool), typeof(Syncfusion.Windows.Tools.Controls.TitleBar));

public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(String propertyName)
{
    if (PropertyChanged != null)
    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}

public bool TitleBarVisible
{
    get { return (bool)GetValue(MainWindow.TitleBarProperty); }
    set
    {
        SetValue(MainWindow.TitleBarProperty, value);
        OnPropertyChanged("TitleBarVisible");
    }
}

please refer the screenshot

1 个答案:

答案 0 :(得分:0)

我没有像这样使用附加的peroperty来实现这个目标,

<强> MainWindow.xaml.cs

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {            
            MainWindow window = sender as MainWindow;
            window.TitleBar.Visibility = Visibility.Collapsed;                        
        } 

<强> MainViewModel

public void HideTitleBar(object obj)
{
    (App.Current.MainWindow as MainWindow).TitleBar.Visibility = Visibility.Visible;
}