'[WPFApplication] .MainWindow'的部分声明不得指定不同的基类

时间:2013-01-15 09:32:59

标签: wpf telerik interop window radwindow

我在`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);代码行中,我必须通过窗口(this)。

因此[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);
    }
}

我该如何克服这个错误?

1 个答案:

答案 0 :(得分:2)

如果您的MainWindowRadWindow,则需要

public partial class MainWindow : RadWindow

因为XAML.cs中的窗口类必须相同:

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

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

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

因此您可以将RadWindow用作MainWindowKB article)并将标准WPF窗口传递给InteropHelper