locked
I need more help with WPF RRS feed

  • Question

  • I have the following files: HomeServerTabExtender.cs that sets up the console tab for WHS, MainTabUserControlWPF.xaml that contains the GUI for the console tab, and MainTabUserControl.cs that is a WinForm with an element host that contains the MainTabUserControlWPF.xaml file. I deploy these files using a WiX project.

     

    My question is: Why does the console tab not display correctly?

     

    If I remove the element host in the MainTabUserControl.cs file and leave everything else unchanged, it will display fine, but once I add the element host, the tab will not appear.

     

    I have tried installing .NET 3.0 and 3.5 on the WHS, but it appears to have no effect. Is there some aspect of WHS that blocks the use of element hosts?

     

    Thank you for your help!

    -Brennan

    Thursday, August 7, 2008 5:36 PM

Answers

  • Actually, it will work I was using WPF with .NET 3.5. I've been playing around with WPF in a WHS console tab and it works pretty well. What I did was create a WinForms control whose sole purpose was to host an ElementHost control. Then create a WPF UserControl that is hosted in that ElementHost then dock the ElementHost into the WinForms control. Though it should work with mixed content in the WinForms control both WPF and regular WinForm controls.

    I created a sample tab control which uses WPF as its main UI. It is pretty well it simply since it displays the WPF render tier of the WHS machine (which on the HP MediaSmart server is tier 0, meaning no hardware accelerated graphics goodness) as well as two buttons. The first of which will do a simple 2 second blur animation on the button when clicked. The second button will will display a 300 by 300 pixel WPF window that displays "Hello World!". If you would like the sample leave reply on this thread and I will either send the sample to you or post a how to post in this thread.

    Also, as a side note there are a few things I found while using WPF on WHS which you might find helpful when buidling your WHS console tab with WPF:
    • WPF will by defualt use its classic theme when running on WHS or more specifically Windows Server 2003. To override this theme with either aero (Vista), royal (XP Media Center), or luna (XP) themes you will need to manually inject the theme's resource dictionary into your WPF control's root resource ditionary or alternatively the application resource dictionary.
      • For Vista's Aero theme stick this code in the constractor of your WPF control
        • Uri uri = new Uri("PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component\\themes/aero.normalcolor.xaml", UriKind.Relative);
                      Resources.MergedDictionaries.Add(Application.LoadComponent(uri) as ResourceDictionary);
    • While you can show a WPF window there are a few caveats that you should be aware of. When a WPF window is open for the first time WHS will not honor the windows setting and will show the window maximized within the console tab even if you explicitly set the window's height and width and set the windows start up location to center. Subsequent times after that however when a WPf window is open WHS will honor those settings.
    • Also, another caveat reguarding windows is that if you click on the console while the window is open the console will cover the window which means you can lose windows. The workaround for this is to set the TopMost property of the window to true.
    • Also, you will not be able to take advantage of WPF's ability to remote its interface over remote desktop so that it is executed locally on the client side, unfortunately. Since, it will be running on Server 2003 and not a build of Vista, maybe when a version of WHS is released on Server 2008 you may be able to take advantage of this feature.
    Hope this helps!
    Friday, August 8, 2008 3:47 AM

All replies

  •  BrennanWatt wrote:

    I have tried installing .NET 3.0 and 3.5 on the WHS, but it appears to have no effect. Is there some aspect of WHS that blocks the use of element hosts?

     

    The WHS Console application is based on the .NET 2.0 Framework. So you can only use .NET 2.0 based functionality for your addin.

    Thursday, August 7, 2008 8:43 PM
    Moderator
  •  

    So are you saying that even though I updated the WHS with .NET 3.0, the console will only allow .NET 2.0 controls?

     

    If so, are there any updates that you're aware of that would allow for an upgrade in features (specifically WPF functionality).

     

    Thanks in advance for your clarification.

     

    -Brennan

    Thursday, August 7, 2008 9:28 PM
  • Actually, it will work I was using WPF with .NET 3.5. I've been playing around with WPF in a WHS console tab and it works pretty well. What I did was create a WinForms control whose sole purpose was to host an ElementHost control. Then create a WPF UserControl that is hosted in that ElementHost then dock the ElementHost into the WinForms control. Though it should work with mixed content in the WinForms control both WPF and regular WinForm controls.

    I created a sample tab control which uses WPF as its main UI. It is pretty well it simply since it displays the WPF render tier of the WHS machine (which on the HP MediaSmart server is tier 0, meaning no hardware accelerated graphics goodness) as well as two buttons. The first of which will do a simple 2 second blur animation on the button when clicked. The second button will will display a 300 by 300 pixel WPF window that displays "Hello World!". If you would like the sample leave reply on this thread and I will either send the sample to you or post a how to post in this thread.

    Also, as a side note there are a few things I found while using WPF on WHS which you might find helpful when buidling your WHS console tab with WPF:
    • WPF will by defualt use its classic theme when running on WHS or more specifically Windows Server 2003. To override this theme with either aero (Vista), royal (XP Media Center), or luna (XP) themes you will need to manually inject the theme's resource dictionary into your WPF control's root resource ditionary or alternatively the application resource dictionary.
      • For Vista's Aero theme stick this code in the constractor of your WPF control
        • Uri uri = new Uri("PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component\\themes/aero.normalcolor.xaml", UriKind.Relative);
                      Resources.MergedDictionaries.Add(Application.LoadComponent(uri) as ResourceDictionary);
    • While you can show a WPF window there are a few caveats that you should be aware of. When a WPF window is open for the first time WHS will not honor the windows setting and will show the window maximized within the console tab even if you explicitly set the window's height and width and set the windows start up location to center. Subsequent times after that however when a WPf window is open WHS will honor those settings.
    • Also, another caveat reguarding windows is that if you click on the console while the window is open the console will cover the window which means you can lose windows. The workaround for this is to set the TopMost property of the window to true.
    • Also, you will not be able to take advantage of WPF's ability to remote its interface over remote desktop so that it is executed locally on the client side, unfortunately. Since, it will be running on Server 2003 and not a build of Vista, maybe when a version of WHS is released on Server 2008 you may be able to take advantage of this feature.
    Hope this helps!
    Friday, August 8, 2008 3:47 AM
  • I would love to see your sample to see how you got everything working. Also, what version of .NET do you have running on your WHS?

     

     

    Thanks,

    Brennan

    Friday, August 8, 2008 5:17 PM
  • Sorry about the late reply but as promised, here is my WPF Console Tab sample for WHS. I've uploaded the project to my pownce account here. You will need to either to sign in or create an account on pownce to download the sample. If you would like an alternative means to download the sample then make a post with the alternative means of contact. The sample requires VS 2008 to open the solution and the .NET 3.5 framework installed on WHS to run the tab.

    I did not make an MSI installer for the project so you will need to manually install the tab by placing the compiled dll into your Windows Home Server directory. Once installed, look for the tab called "WPF on WHS" in the WHS console.

    Note: If you want to debug the sample you can attach a debugger to the console and setup breakpoints in VS. For more info on this you can visit this site which is a very good resource on WHS development.

    A quick overview of the sample:

    The project contains two controls a WinForms control called ElementHostContainerControl and a WPF control called WHSWPFControl. The WinForms control dosen't have any custom logic in it since from the WinForm designer I just draged an ElementHost into the control and docked it in the parent control and set the ElementHost to host the WHSWPFControl.

    The WPF control itself is pretty simple contains and contains a few lables and two buttons which display the WPF render tier, do an animation blur, and open a WPF window respectively. In the code behind file for the WPF control I merge WPF's Aero theme into the control's resource dictionary so that the controls take on the Aero theme instead of the Classic theme WPF defaults to on WHS.

    Also, in the project is a WPF window called HelloWorldWindow which simply has a label centered in a grid that contains the text "Hello World!". The Window itself is set to a fixed width of 300 and a height of 300 with a startup location of center and has the Topmost property set to true.

    Hope you find the sample helpful. If you find any bugs or have any suggestions then leave me a post.
    Saturday, August 9, 2008 1:46 AM
  • Hello Emed,

     

    Must be getting old. Never to old to learn :-)
    I'll certainly have a look at your code. Thanks!

     

     

     

    Saturday, August 9, 2008 8:05 AM
    Moderator
  •  

    emed-

     

    Your sample program looks very similar to the one I created. However, when I placed your .dll into the WHS directory, it failed to appear as a tab. I also built an MSI installer for deployment, but this failed to make the tab appear either, though it installed correctly (according to the WHS console).

     

    I have installed .NET 3.0 and 3.5 on my WHS machine. What is going wrong????

     

     

    Thanks,

    Brennan

    Monday, August 11, 2008 5:58 PM
  • Wow, that's really odd. I know for a fact that the sample works, at least on my system, and I can provide screenshots to prove it.

    If possible can you provide greater details on how exactly the WHS console is failing. Does the entire console crash when it is launched or does the tab simply not appear in the tab list. If it's the former then some type of exception is being thrown by the tab or if the later then there is something wrong with the tab code itself that is preventing  the WHS console from seeing it.

    Can you launch the WHS console through remote debugging using msvsmon.exe from Visual Studio and then break into the tab code while it running in the WHS console? You may be able get some answers that way by stepping through the constructor code for the tab to see what it is doing. It is also a good way to see if the WHS console is even attemping to run the tab at all, no break would mean it is not even trying to run the tab. Also, as a test of the system's .NET seup on the server try building and running a standalone WPF app on it, if the server can run the app then it should be able to run WPF through the WHS console as well.

    Post back when you get the results.
    Hope this helps.
    Monday, August 11, 2008 8:15 PM
  • The console installs the add-in correctly, but the tab fails to appear. The add-in appears in the list of installed add-ins. I will attempt some of the solutions you mentioned and get back to you. It is the element host that the console is having a problem with. If I leave everything unchanged, but delete the element host, the tab displays just fine (though without the host none of the WPF GUI can be seen).

     

    Thanks for your help,

    Brennan

    Monday, August 11, 2008 8:55 PM
  •  

    What version of Windows Home Server are you running? Here is my information:

     

    Windows Home Server Console: 6.0.1500.6

    Build: 3790

    Service Pack: 2

     

    Thanks,

    Brennan

    Thursday, August 14, 2008 6:39 PM
  • Here is my WHS setup.

    WHS Console: 6.0.1800.0 (WHS Power Pack 1)
    .NET Framework Version: 3.5 SP1

    From looking at your WHS Console version you may want to consider running windows update on WHS to install Power Pack 1. It looks like you're running the old version of the console. Also, while your at it you may want to consider installing .NET 3.5 SP1 which recently RTM'ed.

    It includes a number of performance improvements and features for WPF as well a number CLR level performance optimizations, especially for cold starts, which should provide a nice performance boosts for all .NET applications installed on the server, in theory anyway. More info and videos about the update can be found on Channel 9, the direct link to the WPF specific videos is here. The diect link to my favorite video of the series discussing the performance enhancements in the 3.5 SP1 release is here.

    With this post I've also included some screenshots of some of the WPF tabs I've written so far as well a screenshot of my WHS version information.

    WHS Version Info
    WPF on WHS (A shot of the sample WPF tab I posted here)
    uTorrent WPF (A personal uTorrent Tab written in WPF that I'm developing)
    uTorrent WPF - Login Overlay (Shows off some advance things you can do with WPF in the WHS Console)

    Please note that the uTorrent WPF tab I've shown here is something internal that I've been writing in my spare time as a personal learning exercise to become familiar with WPF-WinForms interop as well as WPF in general. There are currently no plans to release it to the public. With that said it does provide a decent example of what you can do with WPF in the WHS console which is the reason why I decided to include some screenshots of it.

    If you want I can post some of my experiences and some of the quirks and workarounds I found using WPF with WHS if you're really serious about
    writing a console tab using WPF.

    As a side note, if you noticed from the screenshots; I am a bit of an anime nut, in case you were wondering

    Edit: I forgot to mention this but did you resolve the problem you had with loading a tab with WPF content? If you did the remote debugging I mentioned in a previous post, did the debugger break on any exceptions while the console was starting, that should have helped you with resolving the loading issue. Also, were you able to run stand alone WPF content on the server?
    Friday, August 15, 2008 3:06 AM