【问题标题】:WPF Alert control similar to StackOverflow类似于 StackOverflow 的 WPF Alert 控件
【发布时间】:2012-05-24 00:30:45
【问题描述】:

寻找类似于 SO 如何使用 Javascript 在浏览器顶部显示警报的 WPF 控件(如此处所述 Notification alert similar to how stackoverflow functions

有一堆 WPF 控件用于显示在系统托盘上方的通知

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

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

但是我希望在当前窗口或用户控件的顶部显示消息,并使用定时淡出来保持消息本地/相关

我是 WPF 新手,所以不知道如何将上面链接的控件定位到当前窗口/用户控件的顶部 - 任何提示/指针都值得赞赏

【问题讨论】:

    标签: c# .net wpf


    【解决方案1】:

    使用 DockPanel 作为窗口内的基本面板。将用户控件设置为 DockPanel.Dock=Top。使用另一个面板来填充剩余空间。

    至于淡出,您可以根据计时器为整个用户控件的不透明度设置动画,当不透明度达到 0 时,将可见性设置为折叠,这样就不会再占用空间了。

    【讨论】:

      【解决方案2】:

      试试这个。

      代码隐藏。

      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>
      

      【讨论】:

        猜你喜欢
        • 2012-06-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多