简体   繁体   中英

How to remove Windows border from WPF UserControl?

To preface this question, I am working on coding the back end of an application whose UI was put together by someone else (I believe using Blend). The application consists of a series of "Screens," whose root element in XAML is "UserControl". There is no use of the "Window" tag anywhere in the source.

What I want to do is remove the Windows border that is added to the outside edge of the application when I run the program. The border currently consists of forward/backward buttons like a web browser, and an X button to close.

All I can find from searches are instructions to add

WindowStyle="None"

to the

<Window>

element. But of course, I don't have one of those, and WindowStyle is not a property of UserControl. Anyone know how to accomplish this with UserControl root elements?

Edit: The StartupUri for the application is

this.StartupUri = new Uri(@"pack://application:,,,/WpfPrototype1.Screens;Component/Screen_1.xaml");

the file it points to does not have a Window tag.

Based on the comments above it seems your MainWindow is created dynamically somewhere, however you can use the Application class to get the applications MainWindow .

var mainWindow = Application.Current.MainWindow;

And you can then set your border style from there

Example:

private void RemoveBorder()
{
    var mainWindow = Application.Current.MainWindow;
    if (mainWindow != null)//should never be
    {
        mainWindow.WindowStyle = System.Windows.WindowStyle.None; // removes top bar (icon, title, close buttons etc)
        mainWindow.AllowsTransparency = true; //removes the border around the outside
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM