我想把一個微調加載和一段時間後(約3,4秒)來隱藏它。我該怎麼做?一段時間後我如何隱藏微調器?
<StackPanel Grid.ColumnSpan="5" Grid.RowSpan="10" Background="White"Name="spinner">
<fa:ImageAwesome Width="80" Icon="Spinner" Spin="True" SpinDuration="2" />
</StackPanel>
我想把一個微調加載和一段時間後(約3,4秒)來隱藏它。我該怎麼做?一段時間後我如何隱藏微調器?
<StackPanel Grid.ColumnSpan="5" Grid.RowSpan="10" Background="White"Name="spinner">
<fa:ImageAwesome Width="80" Icon="Spinner" Spin="True" SpinDuration="2" />
</StackPanel>
這裏是一個純XAML溶液,沒有後面的任何代碼:
<StackPanel ...>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:3"
Value="{x:Static Visibility.Collapsed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</StackPanel.Triggers>
<fa:ImageAwesome .../>
</StackPanel>
設置元件的x:Name
屬性在XAML:
<fa:ImageAwesome x:Name="MyIcon" Width="80" Icon="Spinner" Spin="True" SpinDuration="2" />
而在後面的代碼:
private DispatcherTimer dispatcherTimer;
public MainWindow()
{
InitializeComponent();
//Create a timer with interval of 3 secs
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 3);
MyIcon.Visibility = System.Windows.Visibility.Visible;
// Start the timer
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
MyIcon.Visibility = System.Windows.Visibility.Collapsed;
// Stop the timer
dispatcherTimer.Stop();
}
是的,謝謝!這真的很有幫助! –
不是MVVM ... –
只需注意,您應該調用Start和Stop,或將IsEnabled設置爲true和false。混合看起來很奇怪。 – Clemens
完美!謝謝。 –