Devexpress MVVM NotificationService

XAML代码如下:

<UserControl x:Class="WpfApp1.Views.NotificationService"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" xmlns:ViewModels="clr-namespace:WpfApp1.ViewModels"
             mc:Ignorable="d"
             DataContext="{dxmvvm:ViewModelSource Type=ViewModels:NotificationServiceViewModel}"
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <DataTemplate x:Key="CustomNotificationTemplate">
            <Border Background="White"
                    BorderThickness="1"
                    BorderBrush="Black">
                <StackPanel Orientation="Vertical"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch">
                    <TextBlock HorizontalAlignment="Left"
                               Text="{Binding Caption}"
                               Foreground="Blue"
                               FontSize="20"
                               FontWeight="Bold"
                               Margin="5" />
                    <TextBlock HorizontalAlignment="Center"
                               Text="{Binding Content}"
                               Foreground="Black"
                               FontSize="16"
                               Margin="3" />
                </StackPanel>
            </Border>
        </DataTemplate>
    </UserControl.Resources>
    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:NotificationService x:Name="ServiceWithDefaultNotifications"
                                    ApplicationId="sample_notification_app"
                                    PredefinedNotificationTemplate="ShortHeaderAndTwoTextFields" />
        <dxmvvm:NotificationService x:Name="ServiceWithCustomNotifications"
                                    CustomNotificationTemplate="{StaticResource CustomNotificationTemplate}"
                                    CustomNotificationPosition="BottomRight" />
    </dxmvvm:Interaction.Behaviors>
    <Grid>
        <StackPanel VerticalAlignment="Center"
                    HorizontalAlignment="Center">
            <Button Content="Default notification"
                    Command="{Binding ShowDefaultNotificationCommand}"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Margin="2" />
            <Button Content="Custom notification"
                    Command="{Binding ShowCustomNotificationCommand}"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Margin="2" />
        </StackPanel>
    </Grid>
</UserControl>


对应的MODEL VIEW

    [POCOViewModel]
    public class NotificationServiceViewModel
    {
        [ServiceProperty(Key = "ServiceWithDefaultNotifications")]
        protected virtual INotificationService DefaultNotificationService { get { return null; } }
        [ServiceProperty(Key = "ServiceWithCustomNotifications")]
        protected virtual INotificationService CustomNotificationService { get { return null; } }

        public void ShowDefaultNotification()
        {
            INotification notification = DefaultNotificationService.CreatePredefinedNotification("Predefined Notification", "First line", String.Format("Second line. Time: {0}", DateTime.Now), null);
            notification.ShowAsync();
        }

        public void ShowCustomNotification()
        {
            CustomNotificationViewModel vm = ViewModelSource.Create(() => new CustomNotificationViewModel());
            vm.Caption = "Custom Notification";
            vm.Content = String.Format("Time: {0}", DateTime.Now);
            INotification notification = CustomNotificationService.CreateCustomNotification(vm);
            notification.ShowAsync();
        }
    }
    [POCOViewModel]
    public class CustomNotificationViewModel
    {
        public virtual string Caption { get; set; }
        public virtual string Content { get; set; }
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值