DialogButtonConverter.cs 954 字节
Newer Older
小时後可胖了's avatar
建库  
小时後可胖了 已提交
1 2 3 4 5 6
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using SmartUI.Common.Enum;

小时後可胖了's avatar
小时後可胖了 已提交
7
namespace SmartUI.UI.Converter
小时後可胖了's avatar
建库  
小时後可胖了 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
{
    public class DialogButtonConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is DialogButton dialog) || parameter is null)
                return Visibility.Collapsed;
            if (dialog == DialogButton.OkCancel)
                return Visibility.Visible;
            if (Enum.TryParse<DialogButton>(parameter.ToString(), out DialogButton selected))
            {
                return dialog == selected ? Visibility.Visible : Visibility.Collapsed;
            }
            return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}