I have a xaml view which contains an animation that I put into a content control. In the code behind for the xaml, I load the animation through storyboard find resources. This is fine so far. What I'm having issue is in my xaml there's a button which triggers a relay command from the view model, execute database calls then prompt a message. What I want to achieve is when I click on the button, I would like to show the animation and then when the message box show, i would like to hide the animation. So far no luck.
MainView
<ContentControl Name="loader" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="Test" Command="{Binding TestCommand, Mode=OneWay}" />
</StackPanel>
MainView.cs
public MainView()
{
InitializeComponent();
_loading = new LoadingUC();
_loaderUC = _loading;
showLoading.Content = _loaderUC;
Storyboard showUC = FindResource("Test_Loading") as Storyboard;
showUC.Begin(_loaderUC);
}
TestViewModel
public ICommand TestCommand
{
get
{
return _TestCommand ?? (_TestCommand = new RelayCommand(p => TestSave()));
}
}
private void TestSave()
{
// show loading
if (SaveSuccessFul() == true)
{
//hide loading
MessageBox.Show("Save Completed");
}
}