I’m facing a very strange issue on WPF application. Let me explain clearly what I’ve done.
I’ve Datagrid with selecteditems as check box so user select and click on Load button then the record will load to the database server. During this time I kept spinning image while data loading to the database server. since I’ve lots of records.
By default I’ve kept image to hidden while data loading property change to visible. Whne it comes foreach statement image never shows or if it is visibility by default image shows but never spins… Any ideas or help on this what i’m doing wrong..?
Xaml code…
<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# code..
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;
}
}
You can try wrapping the visibility update in a
Dispatcher.Invokecall to force it to the top of the UI thread and run yourforeachon a background worker thread: