【发布时间】:2011-06-02 19:39:17
【问题描述】:
我有一个列表框,其中用户控件设置为列表框项。在这个列表框中,我有几个网格和两个按钮。
<Grid x:Name="LayoutRoot" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="120" />
<RowDefinition x:Name="personDetailHolder" Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="92.915" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.RowSpan="2"
Grid.ColumnSpan="2"
Margin="0,0,-0.042,0"
Orientation="Vertical"
d:LayoutOverrides="Height">
<Grid Height="117" Margin="3,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="117" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle />
<!-- removed for brevity -->
<Button x:Name="btnViewDetails"
Width="106"
Height="24"
Margin="0,0,3,6"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Click="btnDetails_Click"
Foreground="#FFFBCE2F"
Style="{StaticResource ViewDetailsButton}" />
<!-- Detail section -->
<Grid x:Name="personDetail"
Grid.Row="1"
MinHeight="365"
Margin="0,0,5,-376"
VerticalAlignment="Bottom"
RenderTransformOrigin="0.5,0.5"
Visibility="Collapsed">
<Rectangle />
<!-- removed for brevity -->
<Button x:Name="btnCloseDetails"
Width="123"
Height="24"
Margin="0,8,8,0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Click="btnDetails_Click"
Foreground="#FFFBC42F"
Style="{StaticResource CloseDetailsButton}" />
</Grid>
</Grid>
</StackPanel>
</Grid>
点击事件btnDetails_Click在用户控件后面的代码中调用一个事件
private void btnDetails_Click(object sender, System.Windows.RoutedEventArgs e)
{
UIPanelControl cp = new UIPanelControl();
cp.CheckDetailPanelStatus(this.personDetail, this.personDetailHolder, this.btnViewDetails, this.btnCloseDetails, this.detailAnimation);
}
调用方法
public void CheckDetailPanelStatus(Grid panelName, RowDefinition rowName, Button openButtonName, Button closeButtonName, Storyboard animi)
{
if (panelName.Visibility == System.Windows.Visibility.Visible)
{
panelName.Visibility = System.Windows.Visibility.Collapsed;
rowName.Height = new GridLength(0);
openButtonName.Visibility = System.Windows.Visibility.Visible;
closeButtonName.Visibility = System.Windows.Visibility.Collapsed;
}
else
{
panelName.Visibility = System.Windows.Visibility.Visible;
rowName.Height = new GridLength(380);
openButtonName.Visibility = System.Windows.Visibility.Collapsed;
closeButtonName.Visibility = System.Windows.Visibility.Visible;
animi.Begin();
}
}
这里的目标是向用户返回结果列表。然后,用户可以单击查看其他详细信息按钮展开第二部分,该部分显示有关所选记录的更多详细信息。我正在使用 MVVM 方法,因此命令转到 VM 以促进第二个记录填充。由于动画、可见性等都包含在视图中,因此我决定将这些事件保留在视图代码中。
此解决方案部分有效,因为当我单击按钮时,该部分确实会针对选定的列表框项展开。但是,如果我向下滚动到其他结果,我会发现其他列表框项目会间歇性地扩展。这没有可重复的模式(即每 5 个项目或每隔一个记录)而且我还看到了如果我选择第一个记录并展开它然后向下滚动到下一个记录并备份第一个记录已被重置的实例折叠起来。
我对可能导致此问题的原因感到困惑。
谁能提供我看到这种情况发生的原因或如何防止这种情况发生的任何见解?
【问题讨论】:
标签: silverlight mvvm datatemplate listboxitem