c++/cli 检索 wpf window 结果的最佳方式
c++/cli best way to retrieve wpf window result
我有一个 WPF
window,我从 C++/cli
代码调用它,它工作正常。我需要的是拦截用户操作的最佳方式是什么,我的意思是他是否单击 OK
或 Cancel
。我想做的是在我的 window 中定义一个 Boolean
属性 并根据用户操作设置它。这是我的代码:
MyWindowView^ window = gcnew MyWindowView();
System::Windows::Interop::WindowInteropHelper^ windowInteropHelper = gcnew System::Windows::Interop::WindowInteropHelper(window);
windowInteropHelper->Owner = (IntPtr)AfxGetMainWnd()->m_hWnd;
window->WindowStartupLocation = System::Windows::WindowStartupLocation::CenterScreen;
window->ShowDialog();
if ()
{
//some action
}
else
{
//
}
另外我想知道是否需要删除 window
对象?
Window.ShowDialog
returns 对话框 result。我看不出有任何理由以某种方式获得此结果,这与 C# 或 VB .NET:
不同
System::Nullable<System::Boolean> result = window->ShowDialog();
if (result.HasValue)
{
// OK or Cancel
if (result.Value)
{
// OK clicked
}
else
{
// Cancel clicked
}
}
else
{
// dialog closed via system menu or Alt+F4
}
do I need to delete the window object ?
不,你不知道。请参阅 this 答案。
我有一个 WPF
window,我从 C++/cli
代码调用它,它工作正常。我需要的是拦截用户操作的最佳方式是什么,我的意思是他是否单击 OK
或 Cancel
。我想做的是在我的 window 中定义一个 Boolean
属性 并根据用户操作设置它。这是我的代码:
MyWindowView^ window = gcnew MyWindowView();
System::Windows::Interop::WindowInteropHelper^ windowInteropHelper = gcnew System::Windows::Interop::WindowInteropHelper(window);
windowInteropHelper->Owner = (IntPtr)AfxGetMainWnd()->m_hWnd;
window->WindowStartupLocation = System::Windows::WindowStartupLocation::CenterScreen;
window->ShowDialog();
if ()
{
//some action
}
else
{
//
}
另外我想知道是否需要删除 window
对象?
Window.ShowDialog
returns 对话框 result。我看不出有任何理由以某种方式获得此结果,这与 C# 或 VB .NET:
System::Nullable<System::Boolean> result = window->ShowDialog();
if (result.HasValue)
{
// OK or Cancel
if (result.Value)
{
// OK clicked
}
else
{
// Cancel clicked
}
}
else
{
// dialog closed via system menu or Alt+F4
}
do I need to delete the window object ?
不,你不知道。请参阅 this 答案。