有没有办法在 WPF 中“预渲染”列表而不实际向用户显示?我有一个列表在第一次显示给用户时呈现相当缓慢(几秒钟)。
我想预渲染/预绘制列表,以便向用户显示列表所需的几秒钟时间不明显。我希望在应用程序启动时发生这种情况 - 在显示我的启动画面时。
实现这一目标的最佳方法是什么?
编辑:
这是我的列表项样式。如您所见,目标类型是按钮。该按钮上还设置了一个 RoutedEvent (Command)。
<Style x:Key="Button_ProductFinder_Item" TargetType="Button">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Width="690" Height="181" >
<Image Name="Up" Source="{StaticResource Img_ProductFinder_FriendUp}" Stretch="Uniform"/>
<Image Name="Down" Source="{StaticResource Img_ProductFinder_FriendDn}" Visibility="Hidden" Stretch="Uniform"/>
<Canvas Name="Clip" ClipToBounds="True" Height="162" Width="175" HorizontalAlignment="Left" Margin="0,10,0,0" >
<Image Name="DynamicFriend" Stretch="UniformToFill" Canvas.Left="16" Canvas.Top="-10" HorizontalAlignment="Left" Source="{Binding ImageSource}" Height="162" Width="162" />
<Canvas.RenderTransform>
<TransformGroup>
<TranslateTransform />
</TransformGroup>
</Canvas.RenderTransform>
</Canvas>
<TextBlock Name="DynamicName" Margin="210,69,0,0" Style="{StaticResource ButtonFriend_Textstyle}"
TextWrapping="Wrap" HorizontalAlignment="Left" Width="440" VerticalAlignment="Stretch" Height="Auto"
Text="{Binding ProductName}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Up" Property="Visibility" Value="Hidden"/>
<Setter TargetName="Down" Property="Visibility" Value="Visible"/>
<Setter TargetName="Clip" Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<TranslateTransform Y="2"/>
</TransformGroup>
</Setter.Value>
</Setter>
<Setter TargetName="DynamicName" Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<TranslateTransform Y="2"/>
</TransformGroup>
</Setter.Value>
</Setter>
<Setter TargetName="DynamicName" Property="Foreground" Value="#FFFFFF"/>
<Trigger.EnterActions>
<ctrls:ButtonSoundPlayerAction SoundFile="buttonclick.wav"/>
</Trigger.EnterActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>