代码之家  ›  专栏  ›  技术社区  ›  Eric Smith

在WPF中的WindowsFormsHost中的控件上使用setWindowTheme()?

  •  1
  • Eric Smith  · 技术社区  · 15 年前

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

    在我的wpf应用程序中,我使用windowsformshost作为winforms列表视图的宿主,以便使用 SetWindowTheme() 并应用Windows Vista/7样式。

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

    如何在WPF中实现ListView上的Windows7外观?我不想创建一个定制的样式然后应用它,因为坦率地说,这是太痛苦的屁股继续使用WPF这个应用程序。

    谢谢!:)

    2 回复  |  直到 14 年前
        1
  •  3
  •   Peter Kiers    14 年前

    只需添加以下行:

    [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); 
    }
    
        2
  •  0
  •   Eric Smith    15 年前

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

    推荐文章