Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否在WPF中的WindowsFormsHost控件上使用SetWindowTheme()?_Wpf_Interop_Windowsformshost - Fatal编程技术网

是否在WPF中的WindowsFormsHost控件上使用SetWindowTheme()?

是否在WPF中的WindowsFormsHost控件上使用SetWindowTheme()?,wpf,interop,windowsformshost,Wpf,Interop,Windowsformshost,我有一个我正在开发的应用程序,它与Windows7的设备阶段非常相似。在设备阶段,主标题下有一个ListView,其中包含作为ListViewItems实现的操作 在我的WPF应用程序中,我使用WindowsFormsHost来承载WinForms列表视图,这样我就可以对其使用SetWindowTheme(),并对其应用Windows Vista/7样式 但是,这不起作用,也不能达到与在Windows窗体中使用时相同的效果 如何在WPF中实现Windows 7的列表视图外观?我不想创建一个自定义

我有一个我正在开发的应用程序,它与Windows7的设备阶段非常相似。在设备阶段,主标题下有一个ListView,其中包含作为ListViewItems实现的操作

在我的WPF应用程序中,我使用WindowsFormsHost来承载WinForms列表视图,这样我就可以对其使用
SetWindowTheme()
,并对其应用Windows Vista/7样式

但是,这不起作用,也不能达到与在Windows窗体中使用时相同的效果

如何在WPF中实现Windows 7的列表视图外观?我不想创建一个自定义样式,然后再应用它,因为坦率地说,在这个应用程序中继续使用WPF实在是太麻烦了


谢谢!:)

显然,在仔细研究之后,唯一的答案似乎确实是在WPF中创建自定义设计的控件。

只需添加以下行:

[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)] 
public static extern int SetWindowTheme(IntPtr hWnd, String pszSubAppName, String pszSubIdList); 

.ctor 
{
    System.Windows.Forms.Integration.WindowsFormsHost.EnableWindowsFormsInterop();
    System.Windows.Forms.Application.EnableVisualStyles();

    SetWindowTheme(MyControl.Handle, "Explorer", null); 
}