如何使用 RadWindow 作为 WPF 应用程序的 MainWindow

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11896038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 04:55:46  来源:igfitidea点击:

How to Use RadWindow as MainWindow of WPF application

wpftelerikmainwindowradwindow

提问by Muhammad Ummar

I want to use RadWindow as the main window of my WPF application. So that outer window also take the theme of overall application. I used thisapproach, but after that application is not being shown on Taskbar anymore. After reading different threads I came to know that because RadWindow is not child of Window so that's why its not possible.

我想使用 RadWindow 作为我的 WPF 应用程序的主窗口。这样外窗也以整体应用为主题。我使用了这种方法,但之后该应用程序不再显示在任务栏上。在阅读了不同的线程后,我才知道,因为 RadWindow 不是 Window 的子级,所以这就是不可能的原因。

So What is now I am trying to do, is to hide the outer Window completely somehowand to use RadWindow as a child, but parent of all other controls. Following is XAML

所以现在我想要做的是以某种方式完全隐藏外部 Window并将 RadWindow 用作子项,但所有其他控件的父项。以下是 XAML

<Window x:Class="MyTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        WindowStyle="None"
        Title="MainWindow" >
    <telerik:RadWindow WindowStartupLocation="CenterScreen" Width="Auto" Height="Auto" x:Name="MyRadWindow">
    <Grid>
      <!-- All Controls here -->
    </Grid>
</telerik:RadWindow>
</Window>

But I am unable to completely hide the outer window. It still shows the borders. Then as a second step I have to handle the minimize, maximize and window close events from this RadWidow.

但我无法完全隐藏外窗。它仍然显示边界。然后作为第二步,我必须处理来自 this 的最小化、最大化和窗口关闭事件RadWidow

If anyone have tried this approach please help me out or suggest what would be the better way of doing this?

如果有人尝试过这种方法,请帮助我或建议这样做的更好方法是什么?

The main purpose of doing all this is to Sync the GUI of Outerwindow with the current TelerikTheme.

这样做的主要目的是将 Outerwindow 的 GUI 与当前的 TelerikTheme 同步。

回答by ThorstenHa

There's a simpler solution using the RadWindowInteropHelper like this:

使用 RadWindowInteropHelper 有一个更简单的解决方案,如下所示:

using Telerik.Windows.Controls.Navigation;
public partial class MyRadWindow : RadWindow
{
    public MyRadWindow()
    {
        InitializeComponent();
        RadWindowInteropHelper.SetShowInTaskbar(this, true);
    }
}

回答by vadim

I think you should try to set main class as telerik window instead of nesting inside normal window:

我认为您应该尝试将主类设置为 Telerik 窗口,而不是嵌套在普通窗口中:

<telerik:RadWindow x:Class="MyTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        WindowStyle="None" WindowStartupLocation="CenterScreen" ShowInTaskbar="True"
        Title="MainWindow" >
    <Grid>
      <!-- All Controls here -->
    </Grid>
</telerik:RadWindow>

Don't forget to change base class of MyTest.MainWindow to RadWindow

不要忘记将 MyTest.MainWindow 的基类更改为 RadWindow

EDIT: Sorry didn't notice provided link. You can try hide main window with overriding it style by setting following attributes:

编辑:抱歉没有注意到提供的链接。您可以尝试通过设置以下属性来隐藏主窗口并覆盖它的样式:

WindowStyle="None" Background="Transparent" AllowsTransparency ="True"

回答by kazem

  1. First open the MainWindow.xaml file and replace the Window declaration with RadWindow declaration: <telerik:RadWindow x:Class="RadWindowAsMainWindow.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Loaded="RadWindow_Loaded_1" Header="MainWindow" Height="350" Width="525">... </telerik:RadWindow>
  1. 首先打开 MainWindow.xaml 文件并将 Window 声明替换为 RadWindow 声明: <telerik:RadWindow x:Class="RadWindowAsMainWindow.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Loaded="RadWindow_Loaded_1" Header="MainWindow" Height="350" Width="525">... </telerik:RadWindow>

and in code-behind: `

并在代码隐藏中:`

public partial class MainWindow : RadWindow
    {
     ...
    }

2. Then override OnStartup method of the Application class to show the RadWindow:

2. Then override OnStartup method of the Application class to show the RadWindow:

public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            new MainWindow().Show();
            base.OnStartup(e);
        }
    }

`

`

  1. Then in RadWindowLoad event write this: `

    private void RadWindow_Loaded_1(object sender, RoutedEventArgs e) { var window = this.ParentOfType(); window.ShowInTaskbar = true; }

  1. 然后在 RadWindowLoad 事件中写入:`

    private void RadWindow_Loaded_1(object sender, RoutedEventArgs e) { var window = this.ParentOfType(); window.ShowInTaskbar = true; }

`

`