Select to view content in your preferred language

Removing RichTextBoxes

452
1
06-22-2010 04:17 AM
jonataspovoas
Regular Contributor
I have this code in the xaml:

<StackPanel x:Name="Comentarios" Margin="0,0,0,8" Visibility="Collapsed">
[INDENT]<TextBlock Foreground="Black" FontSize="12" Text=" Comentários do Usuário:" Width="250"
[INDENT]TextWrapping="NoWrap" Height="Auto" HorizontalAlignment="Left" Margin="5,5,0,5" />[/INDENT]
<RichTextBox x:Name="TextoComentario" HorizontalAlignment="Left" FontSize="12" Width="740"
[INDENT]Margin="0,0,0,10" Height="42" VerticalAlignment="Top">[/INDENT]
</RichTextBox>[/INDENT]
</StackPanel>

This creates a StackPanel with a title and a 2 lines RichTextBox for comments (there's a map above it). Then I add more RichTextBox with this c# code:

private void AddComentario_Click(object sender, RoutedEventArgs e)
{
[INDENT]numeroDeComentarios++;
if (numeroDeComentarios <= 7)
{
[INDENT]RichTextBox novo = new RichTextBox();
novo.Height = 42;
novo.Width = 740;
novo.FontSize = 12;
novo.Margin = TextoComentario.Margin;
novo.VerticalScrollBarVisibility = TextoComentario.VerticalScrollBarVisibility;
Comentarios.Children.Add(novo);[/INDENT]
}
if (numeroDeComentarios == 7) AddComentario.Visibility = Visibility.Collapsed;[/INDENT]
}

With this code I dinamicaly add more RichTextBoxes.

Then I was asked to remove them dinamicaly, and I have no idea how...
0 Kudos
1 Reply
by Anonymous User
Not applicable
In the Comentatios is aa collection with a method Remove, you can keep track of those to remove the dynamically.
0 Kudos