Skip to main content

Microsoft Silverlight

Answered Question Silverlight 2 Beta 1 bug: TextBox in a PopupRSS Feed

(0)

Patrick8639
Patrick8639

Member

Member

575 points

150 Posts

Silverlight 2 Beta 1 bug: TextBox in a Popup

Hello,

I'm trying to insert a TextBox in a Popup in order to simulate a dialog box.

When the TextBox is inside the UserControl, it works correctly.

When it is in a popup, the following appears:
 - Typing text is OK.
 - When pressing the Backspace key or the Delete key, two chars are deleted at the same time.
 - When pressing the Left or Right cursor keys, the move is for 2 chars at the same time.
 - When clicking with the mouse to select text, an entire word is selected.

It seems that the messages are processed 2 times in this condition.

Here is the xaml file I'm using to reproduce the problem. No special code behind file:

 <UserControl x:Class="Diary.SettingsPage"
             xmlns="http://schemas.microsoft.com/client/2007"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Width="795"
             Height="500">

    <UserControl.Resources>

      <Style x:Name="Text" TargetType="TextBlock">
        <Setter Property="FontSize" Value="12" />
      </Style>

      <Style x:Name="Label" TargetType="TextBlock">
        <Setter Property="FontSize" Value="12" />
        <Setter Property="HorizontalAlignment" Value="Right" />
        <Setter Property="VerticalAlignment" Value="Center" />
      </Style>

    </UserControl.Resources>
    
    <Grid x:Name="Settings" Background="White">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="100*"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="150" MinWidth="140"/>
        <ColumnDefinition Width="5"/>
        <ColumnDefinition Width="100*"/>
      </Grid.ColumnDefinitions>
      <TextBlock Margin="5,5,5,5" Text="Consultant" Style="{StaticResource Text}"/>
      <TextBlock Margin="5,5,5,5" Grid.Column="2" Text="Possibilités" Style="{StaticResource Text}"/>
      <GridSplitter HorizontalAlignment="Stretch" Margin="0,0,0,0" Grid.Column="1" Grid.RowSpan="3"/>
      <ListBox Margin="0,0,0,0" Grid.Column="2" Grid.Row="1" HorizontalContentAlignment="Stretch" x:Name="lst_Possibilities"/>
      <ListBox HorizontalContentAlignment="Stretch" x:Name="lst_Users" Grid.Row="1"/>
      <StackPanel Margin="5,5,5,5" Grid.Row="2" Orientation="Horizontal">
        <Button Content="Nouveau..." x:Name="btn_NewUser" Margin="0,0,5,0"/>
        <Button Content="Modifier" x:Name="btn_EditUser"/>
      </StackPanel>
      <StackPanel Margin="5,5,5,5" Grid.Column="2" Grid.Row="2" Orientation="Horizontal">
        <Button Content="Nouveau..." x:Name="btn_NewEntry" Margin="0,0,5,0"/>
        <Button Content="Modifier" x:Name="btn_EditEntry" Margin="0,0,5,0"/>
        <Button Content="Supprimer..." x:Name="btn_DeleteEntry"/>
      </StackPanel>
      <Grid Grid.Row="3" Grid.ColumnSpan="3" Margin="5">
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="100*"/>
        </Grid.ColumnDefinitions>
        <Image Width="16" x:Name="img_Status" Height="16" Margin="0,0,10,0" Source="/Images/Work.png">
          <Image.RenderTransform>
            <RotateTransform x:Name="RotateStatus" CenterX="8" CenterY="8" />
          </Image.RenderTransform>
          <Image.Triggers>
            <EventTrigger RoutedEvent="Image.Loaded">
              <BeginStoryboard>
                <Storyboard>
                  <DoubleAnimation Storyboard.TargetName="RotateStatus"
                                   Storyboard.TargetProperty="Angle"
                                   From="0" To="360" Duration="0:0:3"
                                   RepeatBehavior="Forever" />
                </Storyboard>
              </BeginStoryboard>
            </EventTrigger>
          </Image.Triggers>
        </Image>
        <TextBlock x:Name="txt_Status" Style="{StaticResource Text}" Grid.Column="1"/>
      </Grid>

      <!-- Edition d'un utilisateur -->
      <Popup IsOpen="True">
        <Grid Background="#80000000" Width="795" Height="500">
          <Grid.RowDefinitions>
            <RowDefinition Height="50*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="50*"/>
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="50*"/>
          </Grid.ColumnDefinitions>

          <Grid Grid.Row="1" Grid.Column="1">
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="Auto"/>
              <ColumnDefinition Width="5"/>
              <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBlock Style="{StaticResource Label}" Text="Nom:" />
            <TextBox x:Name="txt_ConsName" Width="300" Grid.Column="2" />
          </Grid>

        </Grid>
      </Popup>
    </Grid>

</UserControl>

Patrick8639
Patrick8639

Member

Member

575 points

150 Posts

Re: Silverlight 2 Beta 1 bug: TextBox in a Popup

Hello,

More information about this problem: 

I have added more to code to display the popup with the press of the "New" button, and also to set the focus on the TextBox. The press of the "Cancel" button just hide the popup.

When the popup is displayed for the first time, the text box works as explained in the first post.

When the popup is displayed for the second time, the text box doesn't take the focus (it remains on the button I clicked). In addition when I click on the textbox, no caret is displayed. Finally, it is working correctly now for Backspace, Delete and mouse selection.

Hope to have a workaround for this. 

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP
Answered Question

Re: Silverlight 2 Beta 1 bug: TextBox in a Popup

Yes. I think this is a bug.

<UserControl x:Class="SilverlightApplication5.Page"
    xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="795"
    Height="500">
    <Grid x:Name="Settings" Background="White">
      <Popup IsOpen="True">
        <Grid Background="#80000000" Width="795" Height="500">         
            <TextBox x:Name="txt_ConsName" Width="300" />     
        </Grid>
      </Popup>
    </Grid>
</UserControl>

What about using Canvas or StackPanel or Grid instead of Popup? You can show/hide those layout controls dynamically so you can probably make like a popup window..
 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


FBrink
FBrink

Member

Member

11 points

25 Posts

Re: Re: Silverlight 2 Beta 1 bug: TextBox in a Popup

If you put your content inside a ContentControl this issue should disappear.

<Popup>
 <ContentControl>
  <TextBox></TextBox>
 </ContentControl>
</Popup>

/Flemming Rosenbrandt

jasonxz
jasonxz

Participant

Participant

1752 points

530 Posts

Re: Re: Silverlight 2 Beta 1 bug: TextBox in a Popup

I'm having a similar issue and sticking my TextBox into a ContentControl didn't fix it.

For me, the 1st time I open the Popup, everything works fine.  The 2nd time, it doens't get the focus despite the fact that I explicity tell it to.  At this point I can still type, though.

On the 3rd attempt, I can't get it the focus and it doesn't fire any Key events, either.

I'll stick it in a Canvas tomorrow night if no solution appears here.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities