You can do this via the System.Windows.Interop
namespace which contains a class named HwndSource
.
using System; using System.Windows;
using System.Windows.Interop;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
// Handle messages...
return IntPtr.Zero;
}
}
}
using System.Windows.Interop;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
// Handle messages...
if(msg == )
{ }
return IntPtr.Zero;
}
}
}
MVVM에서 구현하려면 View의 비하인드 코드에 위 코드를 넣으면 된다.
(ex. MainWindows.xaml.cs)
'.NET > WPF' 카테고리의 다른 글
WPF MSDN 참고 목록 (0) | 2014.07.18 |
---|---|
[WPF]데이터를 정렬하는 ListView 샘플 (0) | 2013.07.10 |
[WPF]ListView의 Scrollbar가 자동으로 현재 진행 중인 row에 맞게 아래로 동작 (0) | 2013.07.08 |
데이터 바인딩 개념 (0) | 2013.06.17 |
2,000 Things You Should Know About WPF (0) | 2012.12.27 |