2012-05-23 51 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