Pregunta

I am working in a `WPF\Telerik Project. I have came across a very strange problem, that I can not use a work around, because of the inter-dependency of functionality.

My project has a auto log out functionality and for that I have to use this piece of code as shown below.

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();

    }

in this HwndSource windowSpecificOSMessageListener = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); line of code I have to pass the window(this).

So that the [Window_Name] window has to be implemented using Window since WindowInteropHelper constructor only accepts Window type.

But when I impliments as belows

public partial class MainWindow : Window
{

I get a error,

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

this MainWindow is not a Window its a Telerik window.

XML is shown below.

    <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>
..

This is my 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>

I also tried by using this code as well in App.xaml.cs

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

How should I overcome this error?

¿Fue útil?

Solución

If your MainWindow is a RadWindow, you need

public partial class MainWindow : RadWindow

because the class of your window in XAML and in .cs need to be identical:

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

According to the posts in this thread, RadWindow uses a Window as container that can be accessed like that

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

so you can use your RadWindow as MainWindow (KB article) and pass a standard WPF window to the InteropHelper

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top