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 3660796
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:14:27+00:00 2026-05-19T01:14:27+00:00

I have an application that gets one of its UI controls via an INativeHandleContract

  • 0

I have an application that gets one of its UI controls via an INativeHandleContract from a different AppDomain. When the size of the control changes the FrameworkElement in the host doesn’t get an updated size. I was wondering if there was any way to fix this.

Here is the sample code (the XAML is just a blank window):

public partial class Window1 : Window
{
    private StackPanel m_stackPanel;
    private Expander m_expander;

    private UIElement m_expanderAddIn;

    public Window1()
    {
        InitializeComponent();

        m_stackPanel = new StackPanel { Orientation = Orientation.Vertical };
        m_stackPanel.Background = Brushes.Red;
        m_expander = new Expander
                         {
                             ExpandDirection = ExpandDirection.Right,
                             Background=Brushes.Blue,
                             IsExpanded=true,
                         };
        m_expander.Expanded += CheckStuff;
        m_expander.Collapsed += CheckStuff;

        Rectangle r = new Rectangle {Fill = Brushes.LightGray, Height = 300, Width = 300};

        m_expander.Content = r;

        m_expanderAddIn = FrameworkElementAdapters.ContractToViewAdapter(FrameworkElementAdapters.ViewToContractAdapter(m_expander));

        m_stackPanel.Children.Add(m_expanderAddIn);

        Content = m_stackPanel;
    }

    private void CheckStuff(object sender, RoutedEventArgs e)
    {
        Debug.WriteLine("Expander: " + m_expander.DesiredSize);
        Debug.WriteLine("Add in: " + m_expanderAddIn.DesiredSize);
        Debug.WriteLine("Stack Panel: " + m_stackPanel.DesiredSize);
    }
}

As you expand and collapse the Expander you would expect the height of the StackPanel to change but it doesn’t. Any ideas would be useful, thanks.

  • 1 1 Answer
  • 1 View
  • 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-19T01:14:27+00:00Added an answer on May 19, 2026 at 1:14 am

    That’s really weird and I have no idea why it behaves like that. This is probably just a small example reproducing your problem so maybe this doesn’t help you much but I got your example working with 3 changes.

    1. Wrap the Expander in a “dummy” StackPanel and use that as the root element for m_expanderAddIn instead. This took care of the Height problem for the Expander.
    2. Change the type of m_expanderAddIn from UIElement to FrameworkElement
    3. Bind the Height of m_expanderAddIn to ActualHeight of m_expander

    Code

    public partial class Window1 : Window
    {
        private StackPanel m_stackPanel;
        private Expander m_expander;
    
        private FrameworkElement m_expanderAddIn;
    
        public Window1()
        {
            InitializeComponent();
    
            m_stackPanel = new StackPanel { Orientation = Orientation.Vertical };
            m_stackPanel.Background = Brushes.Red;
            m_expander = new Expander
                             {
                                 ExpandDirection = ExpandDirection.Right,
                                 Background=Brushes.Blue,
                                 IsExpanded=true,
                             };
            m_expander.Expanded += CheckStuff;
            m_expander.Collapsed += CheckStuff;
    
            Rectangle r = new Rectangle {Fill = Brushes.LightGray, Height = 300, Width = 300};
    
            m_expander.Content = r;
            StackPanel stackPanel = new StackPanel();
            stackPanel.Children.Add(m_expander);
    
            m_expanderAddIn = FrameworkElementAdapters.ContractToViewAdapter(FrameworkElementAdapters.ViewToContractAdapter(stackPanel));
    
            Binding binding = new Binding("ActualHeight");
            binding.Source = m_expander;
            m_expanderAddIn.SetBinding(FrameworkElement.HeightProperty, binding);
    
            m_stackPanel.Children.Add(m_expanderAddIn);
    
            Content = m_stackPanel;
        }
    
        private void CheckStuff(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Expander: " + m_expander.DesiredSize);
            Debug.WriteLine("Add in: " + m_expanderAddIn.DesiredSize);
            Debug.WriteLine("Stack Panel: " + m_stackPanel.DesiredSize);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a web application that gets its data from a certain database. The
I have a Visual Studio 2005/ C# ClickOnce application that gets all its data from a
Assume I have a application that stores data,gets data and processes data and stores
We have a custom PHP/MySQL web application that gets updated and copied (using SFTP)
I'm developing an MVC application and I have a routine that gets the currently
I have applications(WinForm) that gets some objects from webservice. After receiving array I transform
I have application that makes different queries with different results so the caching in
I have an application that checks its command line parameters and stores values in
I have an Application object that has a vector of GameChar objects as one
I have two different libraries critical to my application that are dependent on different

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.