WPF TextBox IsReadOnly绑定

时间:2018-06-11 07:05:51

标签: c# wpf textbox multibinding readonly-attribute

以下是IMultiValueConverter我有:

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
  int loggedId = (int)values[0];
  int createdId = (int)values[1];
  DateTime time = (DateTime)values[2];

  TimeSpan span = DateTime.Now.Subtract(time);

  if (loggedId == createdId && span.TotalHours <12)
    return (bool)true;

  return (bool)false;
}

基于它,我想设置文本框的属性IsReadOnly。但是它不起作用,它总是设置为true。

<TextBox.IsReadOnly>
  <MultiBinding Converter="{StaticResource LoggedUserEnabledStyle}">
    <Binding Path="LoggedUser.ID" />
    <Binding Path="HandOverFormList/CreatorID" />
    <Binding Path="HandOverFormList/TimeOfCreation" />
  </MultiBinding>
</TextBox.IsReadOnly>

转换器返回正确的值,就像我将IsReadOnly更改为IsEnabled一样,它运行正常。虽然,我根据值使用另一个转换为颜色代码背景,因此IsEnabled不是最佳选择。

0 个答案:

没有答案
相关问题