2012-05-23 53 views
0

尋找一個WPF控制類似於在使用Javascript瀏覽器的頂部顯示警報如何SO(如這裏Notification alert similar to how stackoverflow functions解釋)WPF警報控制到計算器

有一堆WPF的用於通知其上述顯示控制系統托盤

http://www.hardcodet.net/projects/wpf-notifyicon

http://nickeandersson.blogs.com/blog/2007/12/a-wpf-desktop-a.html

但是我期待在當前窗口或用戶C的頂部顯示該消息ONTROL使用定時淡出,以保持本地消息/相關

我是一個WPF新手,所以不知道如何上面鏈接到當前窗口/用戶控件上方的控件的位置 - 任何提示/指針讚賞

回答

0

使用DockPanel作爲窗口內的基礎面板。將usercontrol設置爲DockPanel.Dock = Top。使用另一個面板填充剩餘的空間。

至於淡出,您可以基於計時器爲整個用戶控件的不透明度設置動畫,並且當不透明度達到0時,將可見性設置爲摺疊狀態,因此不再佔用空間。

0

試試這個。

後面的代碼。

public partial class dtfromdataset : Window 
    { 
     public dtfromdataset() 
     { 
      InitializeComponent(); 


      this.DataContext = this; 

      time.Interval = 5000; 
      time.Elapsed += new ElapsedEventHandler(time_Elapsed); 
      time.Start(); 
     } 
     Timer time = new Timer(); 



     void time_Elapsed(object sender, ElapsedEventArgs e) 
     { 
      Dispatcher.BeginInvoke(new Action(() => 
      { 
       StatusBarText = "Time is " + DateTime.Now.ToString("ddd-MM-yy HH:mm:ss tt"); 
      })); 
     } 

     private DataTable dt = new DataTable(); 

     public string StatusBarText 
     { 
      get { return (string)GetValue(StatusBarTextProperty); } 
      set { SetValue(StatusBarTextProperty, value); } 
     } 

     // Using a DependencyProperty as the backing store for StatusBarText. This enables animation, styling, binding, etc... 
     public static readonly DependencyProperty StatusBarTextProperty = 
      DependencyProperty.Register("StatusBarText", typeof(string), typeof(dtfromdataset), new UIPropertyMetadata("")); 

} 

的XAML

<Grid Name="stackPanel1"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="224*" /> 
     </Grid.RowDefinitions> 
     <TextBlock Name="statusText" 
        Grid.Row="0" 
        HorizontalAlignment="Stretch" 
        Background="Silver" 
        FontSize="20" 
        Text="{Binding Path=StatusBarText, 
            NotifyOnTargetUpdated=True}" 
        TextAlignment="Center"> 
      <TextBlock.Triggers> 
       <EventTrigger RoutedEvent="Binding.TargetUpdated"> 
        <BeginStoryboard> 
         <Storyboard> 
          <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"> 
           <EasingDoubleKeyFrame KeyTime="0" Value="0" /> 
           <EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="1" /> 
           <EasingDoubleKeyFrame KeyTime="0:0:4" Value="1" /> 
           <EasingDoubleKeyFrame KeyTime="0:0:5" Value="0" /> 
          </DoubleAnimationUsingKeyFrames> 
         </Storyboard> 
        </BeginStoryboard> 
       </EventTrigger> 
      </TextBlock.Triggers> 
     </TextBlock> 
</Grid> 
+0

看起來不錯,會嘗試後回 – Kumar