Jakub Siuda
Jakub Siuda

Reputation: 227

WPF: Textblock text in Popup goes outside of the main window

In my example wpf app I've added one button and one popup to the window. The button is in the bottom right corner and the popup has set "PlacementTarget" property to it and "Placement" set to top. The popup consists of one very long textblock.

What I expect this popup will behave is not to go outside of the window and therefore automatically set his "HorizontalOffset" to the appropriate value, but the popup behaves against my intentions.

enter image description here

Here's my xaml file:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication1" x:Name="window" x:Class="WpfApplication1.MainWindow"
    Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <local:Converters x:Key="Converters"/>
</Window.Resources>
<Grid>
    <Button x:Name="button" Content="Button" VerticalAlignment="Bottom" Width="75" HorizontalAlignment="Right"/>
    <Popup Placement="Top" PlacementTarget="{Binding ElementName=button, Mode=OneWay}" IsOpen="True">
        <TextBlock TextWrapping="Wrap" Text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" Background="White"/>
    </Popup>
</Grid>

Do anyone know how to fix it? I've read that this should be default popup behavior to take care of going out of the boundaries, but not in my case. Thanks in advance.

Upvotes: 0

Views: 1469

Answers (1)

Clement Dungler
Clement Dungler

Reputation: 747

Have you tried to set the width of the Popup or Textblock ?

Sorry, I can't write this poor answer as a comment..

Upvotes: 0

Related Questions