【问题标题】:Partial declarations of '[WPFApplication].MainWindow' must not specify different base classes'[WPFApplication].MainWindow' 的部分声明不得指定不同的基类
【发布时间】:2013-01-15 09:32:58
【问题描述】:

我在一个 `WPF\Telerik 项目中工作。我遇到了一个非常奇怪的问题,由于功能的相互依赖性,我无法使用解决方法。

我的项目具有自动注销功能,为此我必须使用如下所示的这段代码。

private void InitializeAutoLogoffFeature()
    {
        HwndSource windowSpecificOSMessageListener = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
        windowSpecificOSMessageListener.AddHook(new HwndSourceHook(CallBackMethod));
        LogOffHelper.LogOffTime = logOffTime;
        LogOffHelper.MakeAutoLogOffEvent += new MakeAutoLogOff(AutoLogOffHelper_MakeAutoLogOffEvent);
        LogOffHelper.StartAutoLogoffOption();

    }

在这HwndSource windowSpecificOSMessageListener = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); 行代码中,我必须通过窗口(@98​​7654324@)。

因此[Window_Name] 窗口必须使用Window 来实现,因为WindowInteropHelper 构造函数只接受Window 类型。

但是当我暗示如下时

public partial class MainWindow : Window
{

我收到一个错误,

Partial declarations of '[WPFApplication].MainWindow' must not specify different base classes

这个MainWindow 不是Window 它是Telerik window

XML 如下所示。

    <telerik:RadWindow x:Class="[WPFApplication].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"
        Header="POS" Height="820" Width="1280" 
        WindowStartupLocation="CenterScreen">

    <telerik:RadWindow.Resources>
..

这是我的 App.xaml

<Application x:Class="[WPFApplication].App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         StartupUri="MainWindow"
         >

<Application.Resources>

</Application.Resources>

我也尝试在App.xaml.cs中使用此代码

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

我应该如何克服这个错误?

【问题讨论】:

标签: wpf telerik interop window radwindow


【解决方案1】:

如果您的MainWindowRadWindow,则需要

public partial class MainWindow : RadWindow

因为XAML.cs 中的窗口类需要相同:

<telerik:RadWindow x:Class="[WPFApplication].MainWindow" ...>
         ^^^^^^^^^

根据this thread中的帖子,RadWindow使用Window作为容器,可以这样访问

var window = this.ParentOfType<Window>();  

这样您就可以将 RadWindow 用作 MainWindow (KB article) 并将标准 WPF 窗口传递给 InteropHelper

【讨论】:

  • 是的,这是正确的,但由于我必须传递 Window 类型,我无法实现 RadWindow,我是否必须更改我的实现,或者是否有解决方法。 :(
  • 好的,这是另一个问题 - 也许你应该为此打开一个新问题(获取 RadWindow 的句柄)。
  • @Diode 我更新了我的答案,以便回答两个问题:-) 希望这会有所帮助
  • 你是一个救生员。非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多