我想装一个旋转器装载一段时间(大约3,4秒)来隐藏它。我该怎么办?
<StackPanel Grid.ColumnSpan="5" Grid.RowSpan="10" Background="White"Name="spinner">
<fa:ImageAwesome Width="80" Icon="Spinner" Spin="True" SpinDuration="2" />
</StackPanel>
答案 0 :(得分:2)
这是一个纯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>
答案 1 :(得分:1)
在XAML中设置元素的x:Name
属性:
<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();
}