2025-08-15 16:34:31 +08:00

59 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
namespace SWS.CAD.Views.CustomControl
{
/// <summary>
/// 使用bool控制隐藏显示控件
/// </summary>
public class VisibilityValueConverter : IValueConverter
{
/// <summary>
/// 当值从绑定源传播给绑定目标时调用方法Convert
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
if (parameter != null)
{
string tempStr = parameter.ToString();
string valueStr = value.ToString();
if (valueStr == tempStr)
{
return Visibility.Visible;
}
else
{
return Visibility.Collapsed;
}
}
}
return Visibility.Collapsed;
}
/// <summary>
/// 当值从绑定目标传播给绑定源时调用此方法ConvertBack方法ConvertBack的实现必须是方法Convert的反向实现。
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}