0
votes

I have this very simple ChildWindow:

<Grid x:Name="LayoutRoot" Margin="2">
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
    <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />
    <ScrollViewer Width="378">
        <StackPanel>
            <TextBlock x:Name="txtFracture" HorizontalAlignment="Left" Margin="10,10,10,10" TextWrapping="Wrap" VerticalAlignment="Top" Width="358"/>
        </StackPanel>
    </ScrollViewer>
</Grid>

My problem is that the text in the TextBlock is getting clipped on the right side. (I originally didn't have the StackPanel in there - that was just an experiment.) I have added more and more to the Margin.Right, but it doesn't help. The Scroll bar itself isn't stepping on the text, the text just drops a bunch of pixels as it gets to the right of the block. Sometimes, it isn't even whole letters that are getting clipped. See anything?

Also, if I change the HorizontalAlignment from Left to Center, I get the pixel-clipping on both sides of the block.

Also, if I remove the ScrollViewer altogether, the clipping is still there, so it isn't his fault, either.

2

2 Answers

1
votes

I notice you have texblock width as constant and you need margin of 10 on all side. In this case ScrollViewer ScrollBar clips your TextBlock. Possible solution is 1. Remove width on textblock and set alignment stretch.

try this

   <ScrollViewer Width="378" HorizontalScrollBarVisibility="Disabled"  VerticalScrollBarVisibility="Auto">
         <TextBlock x:Name="txtFracture"  HorizontalAlignment="Stretch" Margin="10,10,10,10" TextWrapping="Wrap" VerticalAlignment="Stretch" 
                    Text="Testing"/>   
    </ScrollViewer>
1
votes

Turns out that this works:

    <ScrollViewer Width="378" >
        <StackPanel>
            <TextBlock x:Name="txtFracture" Margin="10,10,10,10" TextWrapping="Wrap" />
        </StackPanel>
    </ScrollViewer>

As far as I can tell, the actual culprit was the explicitly set TextBlock Width.