0

The output window

I have created 1 Winform in that placed one Winform user control. In user control of designer written below code.

Here UC_WPF_UC1 is another user control which is having only a textblcok with width 900 and hosted this WPF user control in element host of width 920 still the text block text cropping.

Text is "This is wpf UC textblock which is having width 900, this is hosted in winform elementhost which is of width 920" which shows properly in xaml design UI file before running application.

I have already tried Dock to fill and some other solution but no luck..

XAML code

<UserControl x:Class="WindowsFormsApp3.UserControl2"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WindowsFormsApp3"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="900">

        <Border Margin="0,0,0,0" BorderThickness="0">
            <Grid Background="#FFFFFF">
                <TextBlock  Foreground="#333333"  FontSize="18" VerticalAlignment="Center" >This is wpf UC textblock which is having width 900, this is hosted in winform elementhost which is of width 920</TextBlock>
            </Grid>
            </Border>
</UserControl>
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
santhosh
  • 9
  • 3
  • The only code you've shown us is the code that is generated by the Designer. Why don't you show us the XAML? – Robert Harvey Mar 19 '21 at 16:07
  • I have added XAML please check – santhosh Mar 19 '21 at 16:11
  • Your width isn't 900. That's a Designer width; it's a convenience for the XAML designer to display the control for you. If you want to set the actual width, use `Width`. – Robert Harvey Mar 19 '21 at 16:27
  • There's no `TextWrapping` set there. Also see [DPI Awareness - Unaware in one Release, System Aware in the Other](https://stackoverflow.com/a/50276714/7444103) – Jimi Mar 19 '21 at 16:27
  • If we set width instead of designer width still the same issue, and I don't want to wrap it since that perfectly fit in WPF User control. – santhosh Mar 19 '21 at 17:05
  • Have you read the notes in the post I've linked? Anyway, if you want to change the Width of that Child control, set it's Width to match the Width of the ElementHost: e.g. `(elementHost1.Child as FrameworkElement).Width = elementHost1.Width;`. You can use a DockPanel to dock the child Control of your UserControl, so it will stretch and expand when needed. -- Don't be surprised if you, at run-time, notice that some measures are not the same you have set at design-time if your app is not DpiAware. -- Also, it's understood that you designed your Form at 100% scaling. Did you? – Jimi Mar 19 '21 at 18:30

0 Answers0