【发布时间】: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); 行代码中,我必须通过窗口(@987654324@)。
因此[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);
}
}
我应该如何克服这个错误?
【问题讨论】:
-
我认为您需要使用覆盖
OnStartup的方法,而不使用StartupUri(请参阅telerik.com/support/kb/wpf/window/radwindow-as-main-window.aspx)
标签: wpf telerik interop window radwindow