我的评论部分有评论,每个评论都可以留下回复。它看起来像这样:
<ListBox x:Name="list" ScrollViewer.VerticalScrollBarVisibility="Hidden" ItemsSource="{Binding Comments}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="comment" FontSize="15" Foreground="Black" Text="{Binding Text}" TextWrapping="Wrap" Margin="0,1,0,5" Padding="{Binding Depth, Converter={StaticResource LevelToPaddingConverter}, ConverterParameter=15}"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="author" Style="{StaticResource commentInfo}" Text="{Binding UserId, Converter={StaticResource UserIdToUserNameConverter}}" Padding="{Binding Depth, Converter={StaticResource LevelToPaddingConverter}, ConverterParameter=15}"/>
<TextBlock Text="," Style="{StaticResource commentInfo}"/>
<TextBlock x:Name="timeAgo" Style="{StaticResource commentInfo}" Text="{Binding CreatedAt, Converter={StaticResource TimestampToAgoConverter}}"/>
</StackPanel>
<!-- THIS BUTTON --><HyperlinkButton x:Name="reply" Grid.Column="1" FontSize="10" Foreground="Blue" Content="Reply" HorizontalAlignment="Right" Tapped="reply_Tapped"/>
<StackPanel x:Name="replyBox" Visibility="Collapsed" Margin="0,19,0,0">
<TextBox PlaceholderText="Write Comment..." FontSize="11" BorderBrush="Gray" BorderThickness="1" Margin="0,0,0,3" Height="50" GotFocus="TextBox_GotFocus" LostFocus="commentBox_LostFocus" TextWrapping="Wrap"/>
<Button Content="Post Reply" FontSize="12" Background="CornflowerBlue" BorderThickness="0" Style="{StaticResource ButtonStyle1}" Width="75" Height="25" HorizontalAlignment="Right" Tapped="PostCommentButton_Tapped"/>
</StackPanel>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
当用户点击该按钮时,可以看到TextBox
和Button
以进行纪念。但是,如果用户在其他评论上点击回复,则有两个{{1}}可见(每个用于相关评论)。但我希望当用户点击回复到另一条评论时,之前的TextBox
会崩溃,因此当时只能看到一个TextBox
。我怎么能这样做?
答案 0 :(得分:0)
我找到了解决方案。我遍历控制中的所有$('body, html')
并找到名称为 replyBox 的那些,然后我将它们折叠。
我是这样做的:
StackPanels
foreach (StackPanel sp in FindVisualChildren<StackPanel>(this))
{
if (sp.Name == "replyBox")
{
sp.Visibility = Visibility.Collapsed;
}
}
//and here showing function for the one I wnat to be visible
函数看起来像这样:
FindVisualChildren
我从this answer获得了想法