我有一個Silverlight 5 OOB應用程序。我想創建'敬酒'。由於限制,我不想使用NotificationWindows。如何將我的Silverlight 5窗口滑動到屏幕上?
我試過創建一個S5窗口並將其滑動到屏幕上。 [原油,但它是一個開始。]如果我在主窗口中使用一個按鈕觸發創建,而另一個按鈕觸發動畫,它就可以工作。如果我把動畫放到第一個方法中,那麼窗口就會出現,不動畫。有誰知道我可以如何做這項工作。
要重新創建,在MainPage.xaml中網格內,加:
<Button Content="Show" Height="23" HorizontalAlignment="Left" Margin="12,12,0,0"
Name="show" VerticalAlignment="Top" Width="75" Click="show_Click" />
<Button Content="Move" Height="23" HorizontalAlignment="Left" Margin="12,41,0,0"
Name="move" VerticalAlignment="Top" Width="75" Click="move_Click" />
裏面MainPage.xaml.cs中,添加:
private Window toastWindow;
private void show_Click(object sender, RoutedEventArgs e)
{
toastWindow = new Window();
toastWindow.Width = 280;
toastWindow.Height = 58;
toastWindow.Left = 975;
toastWindow.Top = 755;
toastWindow.WindowStyle = WindowStyle.None;
toastWindow.WindowState = WindowState.Normal;
toastWindow.Content = new Toast();
toastWindow.Show();
toastWindow.Activate();
//for (int i = 0; i < 20; i++)
//{
// toastWindow.Top = toastWindow.Top - 5;
// System.Threading.Thread.Sleep(25);
//}
}
private void move_Click(object sender, RoutedEventArgs e)
{
for (int i = 0; i < 20; i++)
{
toastWindow.Top = toastWindow.Top - 5;
System.Threading.Thread.Sleep(25);
}
}
您還需要一個UserControl叫做吐司(在Toast.xaml中),其中我給了LayoutRoot Grid一個背景顏色,以至於很明顯,即使通過開始欄,Width =「300」Height =「100」。
在Silverlight 5屬性頁面上,您需要啓用運行在瀏覽器之外的應用程序和在瀏覽器之外的設置集當在瀏覽器之外運行時需要提升信任。
如果您運行它並點擊顯示,您會看到開始欄/時鐘區域後面的烤麪包。如果您點擊移動,它會向上滑動。如果取消註釋show_Click方法的結束並再次運行它並單擊顯示,它將顯示在其最終位置而不會滑動。
任何想法?
P.S.最終,我希望能夠在任何時候在屏幕上擁有多個具有獨立生命週期的「切片」。
是的。使用DispatcherTimer使其消失。謝謝。 – SGarratt 2012-07-12 15:36:12
另一種解決方案可能是使用VisualStateManager來執行動畫,但對於您的情況可能會更復雜。 – jv42 2012-07-12 15:41:37