0

I have winform hosting WPF control text block where the contents of text block is dynamic. I want to set the height of the text block based on content. mean while text block is hosted in windows usercontrol (TitleBarHost) and in turn this windows control is dynamically added in another winform at run time. Below is piece of code where control is added dynamically.

Control titleBar = new TitleBarHost(titleInfo);                        
(titleBar as ICustomUI).Initialize(_application, extraData);
panelHeader.Controls.Add(titleBar);
titleBar.Dock = DockStyle.Top;

TitleBarView.xaml

<Grid>
    <TextBlock x:Name="txtTitleBar" Text="{Binding Text}" Style="{StaticResource TextBlockStyle}"/>
</Grid>

TitleBarHost.cs

    public void Initialize(object application, object configurationData)
    {
        m_Model = new TitleBarModel(this.titleInfo, application, configurationData);
        m_ViewModel = new TitleBarViewModel(m_Model);

        m_View = new TitleBarView { DataContext = m_ViewModel };

        if (m_ViewModel != null)
        {
            m_View.FormatString(m_ViewModel.Text);
        }

        elementHost1.Child = m_View;
    }

I need to set the text block height dynamic based on content. I tried to use the ActualHeight prop of text block but doesn't work. Also tried using height Auto, doesn't works!

13
  • I tried to use the ActualHeight prop of text block but doesn't work. Also tried using height Auto, doesn't works!... those are very poor descriptions and do not help us to understand your problem. Your question is also unclear as a WPF TextBlock automatically adjusts its size to its content.
    – Sheridan
    Mar 5, 2015 at 17:43
  • apologies... I mean i tried setting the 'titleBar' height by taking the ActualHeight property of the text box. And to answer to your second question, you are correct. The height of WPF control textblock will set auto, but since this control is hosted in winform usercontrol, its leaving a blank space if the text content is less. Hope i made a clear statement now!
    – Chethan
    Mar 5, 2015 at 19:27
  • So you want to adjust the size of the WinForms control?
    – Sheridan
    Mar 6, 2015 at 9:02
  • Exactly, and i am trying to assign the ActualHeight of textblock(WPF control) to the height of the "panelHeader"
    – Chethan
    Mar 6, 2015 at 19:48
  • Where's your ElementHost control?
    – Sheridan
    Mar 9, 2015 at 9:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.