Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3457812
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:54:22+00:00 2026-05-18T09:54:22+00:00

I have a problem with a WPF control that I’m trying to host in

  • 0

I have a problem with a WPF control that I’m trying to host in an ElementHost in a WinForms app. The control is a lookless custom control that I originally developed in a separate test project, which was a WPF app. In there it obviously works fine, but in my WinForms app all I get is a blank grey box where the ElementHost is displayed.

Here’s my C# code for creating, populating, and adding the ElementHost to the parent Control:

// This is my WPF control
m_TabHostPanel  = new TabHostPanel();
m_ElementHost  = new ElementHost
                 {
                     Child = m_TabHostPanel,
                     Dock = DockStyle.Top,
                     Height = 34
                 };
this.Controls.Add( m_ElementHost );

The parent control contains other WinForms controls that are added and removed at runtime, as needed. These are all hosted singly with their Dock set to DockStyle.Fill. Thus, every time I add one I send the ElementHost to the back of the Z-order to make sure it renders correctly:

m_ElementHost.SendToBack();

Thus, I know I’m not running into an airspace problem, or anything like that.

The one thing I did wonder about is this: in the original project the styles for all my lookless controls were merged into the resource dictionary for the application in App.xaml, like this:

<Application x:Class="WpfTestApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Application/UserInterface/DataTemplates/TabModelDataTemplate.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/HoverablePressableButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/MiniControlButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabCloseButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabScrollLeftButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabScrollRightButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabListDropDownButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabHostComboBoxStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabButtonStyle.xaml"/>
                <ResourceDictionary Source="Application/UserInterface/Styles/TabHostPanelStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

I’ve migrated App.xaml to my WinForms project, but the build action is set to Page. If I set it to ApplicationDefinition I get an error saying that the application has multiple entry points, which makes sense, but I’m wondering then if the styles, etc., are being picked up. If not this might explain why I’m getting a blank grey rectangle where my control should be because, without these, there’s nothing to define its look. So maybe the question is, how do I get these styles into my WinForms application so that my WPF controls can see them?

I should probably also mention that this is running on .NET Fx 3.5.

Anyway, for now I’m perplexed, so any help would be gratefully received.

Many thanks!

Bart

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:54:22+00:00Added an answer on May 18, 2026 at 9:54 am

    Thanks for replying, but I think you may misunderstand me: I’m trying to use a custom element, whose resources are normally in the Application object, not insert the application itself into the ElementHost.

    Fortunately, I’ve found an answer:

    http://drwpf.com/blog/2007/10/05/managing-application-resources-when-wpf-is-hosted/

    Short version:

    • Set build action for App.xaml to Page
    • In the code behind for App.xaml create a default constructor that just calls InitializeComponent()
    • When the WinForms app starts up, just create an instance of the App class.

    And then it’s all good: my WPF control appears as it should.

    Now, why is it I only find the answer after I’ve posted to StackOverflow?

    Thanks again,

    Bart

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with my WPF program. I'm trying to create an object
I have a button with a transparent background on a wpf window. Problem is,
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem when I try insert some data to Informix TEXT column via
I do not have problem as such but I am quite new to Ruby.
I have a problem using the Java search function in Eclipse on a particular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.