我有一个UserControl
由几个 boundItemsControl
和 组成的strings
,并且根据按下的按钮,显示不同的数据。Button
以下是的点击事件之一的示例:
private void LeftPreviousScoresButton_Click(object sender, RoutedEventArgs e)
{
if (m_previousScoresWindow.Visibility == Visibility.Visible)
{
m_previousScoresWindow.Hide();
}
else
{
WindowTitle = "Left Side";
PreviousScoresA = m_previousLeftWristErosionScoresReaderA;
PreviousScoresB = m_previousLeftWristErosionScoresReaderB;
m_previousScoresWindow.Show();
}
}
有几个这样的点击事件监听器分配WindowTitle
, PreviousScoresA
, 和PreviousScoresB
相关的数据。然后UserControl
像这样绑定到它们:
<ItemsControl Height="Auto" Width="Auto"
ItemsSource="{Binding ElementName=ParentForm, Path=PreviousScoresA}"
Grid.Row="1" />
<ItemsControl Height="Auto" Width="Auto"
ItemsSource="{Binding ElementName=ParentForm, Path=PreviousScoresB}"
Grid.Row="2" />
<TextBlock FontSize="16" FontWeight="Bold" Height="25"
Margin="5" HorizontalAlignment="Center" Foreground="Black"
Text="{Binding ElementName=ParentForm, Path=PreviousScoresWindowTitle}" />
但是,当打开窗口时,旧数据会显示一秒钟,然后再用当前数据更新。我什至尝试在调用时添加这些调用Hide()
,Window
但似乎没有帮助:
WindowTitle = String.Empty;
PreviousScoresA = new ObservableCollection<PreviousScoreData>();
PreviousScoresB = new ObservableCollection<PreviousScoreData>();
有什么方法可以确保Show()
在绑定数据更新之前不会调用它?谢谢。