Skip to main content

Microsoft Silverlight

ScrollViewer layout bug with TextBoxRSS Feed

(0)

Mikernet123
Mikernet123

Member

Member

0 points

3 Posts

ScrollViewer layout bug with TextBox

Hi,

This problem is driving me up the wall.  I thought it was something I was doing, so I created a quick test application to see if I can reproduce it, and sure enough I can.  Shown here is just a simple situation where this bug is visible, but it wrecks havoc on my much more complex custom control.

When you hide the textbox (using the hide button), scroll, then show the textbox, the layout system goes out of whack and starts doing crazy things.  I have a custom control that has a hidden textbox which it shows upon focusing, and this bug is really creating a problem here.

 Here is the code:

  

<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	x:Class="SLTest.Page"
	Width="572" Height="456" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

	<Grid x:Name="LayoutRoot" Background="White">
		<ScrollViewer Margin="0,0,0,0" Width="400" Height="300">
			<Canvas Height="1000" Width="1000">
				<TextBox Height="143" x:Name="tbTestText" Width="169" Canvas.Left="24" Canvas.Top="54" Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis rutrum enim vel arcu volutpat tincidunt. Sed faucibus eleifend magna ac placerat. Donec cursus blandit odio, quis dapibus lacus suscipit sit amet. Phasellus rutrum dapibus odio, et accumsan ligula scelerisque sit amet. Maecenas quis magna nec libero ultricies molestie. Nullam convallis est vel massa congue facilisis ac ut lorem. Phasellus tincidunt vestibulum dui. Proin fermentum libero ut augue bibendum ullamcorper. Sed quis lorem lacus. Nullam auctor lacinia suscipit" TextWrapping="Wrap"/>
			</Canvas>
		</ScrollViewer>
		<Button Height="22" HorizontalAlignment="Left" Margin="11,11,0,0" VerticalAlignment="Top" Width="43" Content="Show" x:Name="btnShow" Click="btnShow_Click"/>
		<Button Height="22" Width="43" Content="Hide" HorizontalAlignment="Left" Margin="69,11,0,0" VerticalAlignment="Top" d:LayoutOverrides="Width, Height" x:Name="btnHide" Click="btnHide_Click"/>
	</Grid>
</UserControl>

 And in the code-behind file:

 

        private void btnShow_Click(object sender, RoutedEventArgs e)
        {
            tbTestText.Opacity = 100;
        }

        private void btnHide_Click(object sender, RoutedEventArgs e)
        {
            tbTestText.Opacity = 0;
        }

 

 Regards,

Mike

Ag.
Ag.

Member

Member

101 points

19 Posts

Re: ScrollViewer layout bug with TextBox

Use Visibility property of the control to show/hide it 

private void btnShow_Click(object sender, RoutedEventArgs e)
{
    tbTestText.Visibility = Visibility.Visible;
}

private void btnHide_Click(object sender, RoutedEventArgs e)
{
    tbTestText.Visibility = Visibility.Collapsed;
}
   

Best Regards

Valery Sarkisov

Mikernet123
Mikernet123

Member

Member

0 points

3 Posts

Re: ScrollViewer layout bug with TextBox

That might work in some situations, but not in our case.  We animate on the opacity to smoothly fade in the control, and the user actually has to be able to interact with the textbox while it is invisible, so Visibility.Collapsed won't work.  Using Visibility also causes odd behaviour when switching between visual states that both make the textbox visible - for some reason it flashes back to collapsed and then back to visible, even though it is going directly between two states that have it set to visible.  This causes all sorts of problems maintaining focus on the textbox between these two states.

Also, as I mentioned, this is just a simple demo to demonstrate the problem.  It's much more difficult to circumvent this problem in my actual scenario.  It does much wackier things within the complex control.

mhaggag
mhaggag

Member

Member

308 points

59 Posts

Re: ScrollViewer layout bug with TextBox

I tested the XAML/code above on SL3 vs the current build of SL4. The problem appears to have been fixed. I want to make sure we are talking about the same problem, though:

In SL3, when scrolling the containing ScrollViewer and showing the TextBox, the TextBox's outline (its ScrollViewer) would show up in the wrong place inside the containing ScrollViewer. Is that what you're seeing?

Muhammad Haggag.
SDE, Silverlight (Text feature team)

Mikernet123
Mikernet123

Member

Member

0 points

3 Posts

Re: ScrollViewer layout bug with TextBox

Yes, I believe that was the issue.  Hopefully all aspects of this bug were taken care of - it did much wierder things in the custom control I was writing.  Not only was the outline of textbox's scrollviewer in the wrong place, but the text in the scollviewer would move around seemingly randomly and mouse clicks weren't being registered in the right place.

mhaggag
mhaggag

Member

Member

308 points

59 Posts

Re: ScrollViewer layout bug with TextBox

OK. I've created an Outlook item on myself to check back on the topic once we make a public release to make sure you don't see any other problems.

Also, I apologize for the very late response--I was busy working on SL4 even before we shipped SL3, and was relying on other team members to check for bug reports. Guess they were doing the same, and this slipped through the cracks =/

Muhammad Haggag.
SDE, Silverlight (Text feature team)
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities