我在 WPF 应用程序上遇到了一个非常奇怪的问题。让我清楚地解释我做了什么。
我将 Datagrid 与 selecteditems 作为复选框,因此用户选择并单击“加载”按钮,然后记录将加载到数据库服务器。在此期间,我在将数据加载到数据库服务器时不断旋转图像。因为我有很多记录。
默认情况下,当数据加载属性更改为可见时,我将图像保持为隐藏状态。当它出现时 foreach 语句图像永远不会显示,或者默认情况下它是可见性的图像显示但从不旋转......任何想法或帮助我做错了什么......?
Xml代码...
<Button Content="Load" Height="23" HorizontalAlignment="Left" Margin="1042,83,0,0"
Name="btnSaveData" Visibility="Hidden" VerticalAlignment="Top" Width="75"
Cursor="Hand" Click="btnSaveData_Click" Foreground="Green"
Background="#FFB0D3D3" FontWeight="Bold" FontSize="14"/>
<Image Height="25" HorizontalAlignment="Left" Margin="1012,83,0,0" Name="imgSpin5"
Stretch="None" RenderTransformOrigin="0.5,0.5" Visibility="Hidden"
VerticalAlignment="Top" Width="24"
Source="/LoadDataSource;component/Images/Spin5.png">
<Image.RenderTransform>
<RotateTransform x:Name="TransRotate" Angle="0"/>
</Image.RenderTransform>
<Image.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<BeginStoryboard>
<Storyboard TargetProperty="Angle">
<DoubleAnimation Storyboard.TargetName="TransRotate"
Storyboard.TargetProperty="Angle" By="360"
Duration="0:0:1" AutoReverse="False"
RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
C#代码..
MessageBoxResult result = MessageBox.Show("Do you want to Load Selected items?",
"Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Information);
if (result == MessageBoxResult.Yes)
{
imgSpin5.Visibility = Visibility.Visible;
foreach (CType ctp in dgAttributes.ItemsSource)
{
if (ctp.IsSelected)
imgSpin5.Visibility = Visibility.Visible;
}
}