【问题标题】:How to Use RadWindow as MainWindow of WPF application如何使用 RadWindow 作为 WPF 应用程序的 MainWindow
【发布时间】:2012-08-07 10:10:02
【问题描述】:

我想使用 RadWindow 作为我的 WPF 应用程序的主窗口。使外窗也以整体应用为主题。我使用了this 方法,但之后该应用程序不再显示在任务栏上。在阅读了不同的线程后,我才知道,因为 RadWindow 不是 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>

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

如果有人尝试过这种方法,请帮助我或提出更好的方法?

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

【问题讨论】:

    标签: wpf telerik mainwindow radwindow


    【解决方案1】:

    我认为您应该尝试将主类设置为 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>
    

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

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

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

    【讨论】:

    • 感谢@vadim,您的建议,它正在根据我的要求创建一个无铬窗口,但是调整大小、最大化和最小化功能将如何工作?
    • 当您覆盖默认样式时,您必须自己提供此功能。也许嵌套的 RadWindow 可以帮助解决这个问题?另外我认为您应该尝试找到在任务栏中显示 RadWindow 的解决方案,而不是将其用作嵌套窗口。
    • 我将继续使用嵌套窗口方法,因为RadWindow 不是Window 类型,所以框架不会接受它作为Window。 Telerik 还提到 RadWindow 并非设计为父窗口。
    • 花了一些时间,几次尝试后,我成功地实现了所需的场景,谢谢@vadim,你的建议对我有用,我使用了你建议的方法。我能够在任务栏中显示RadWindowRadWindow 在用作父窗口时使用Window 作为其父窗口,即 chromeless,所以您需要做的就是获取实例该窗口使用ParentOfType&lt;Window&gt;() 并将其显示在任务栏中。
    • 使用最新的 Telerik 控件,使用下面 ThorstenHa 的回答中描述的 RadWindowInteropHelper 解决方案。
    【解决方案2】:
    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"> ... &lt;/telerik:RadWindow&gt;

    在代码隐藏中: `

    public partial class MainWindow : 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. 然后在 RadWindowLoad 事件中写下: `

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

    `

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

      • 这也可以在 xaml 中完成:xmlns:navigation="clr-namespace:Telerik.Windows.Controls.Navigation;assembly=Telerik.Windows.Controls.Navigation" navigation:RadWindowInteropHelper.ShowInTaskbar="真”见:celticcodingsolutions.com/Blog/post/2014/05/22/…
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多