0
<Border Grid.Row="1" Background="Gray" Padding="7">
  <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,30,0">
    <optimumScheduler:LookUpOKButton Grid.Row="1" Content="OK" HorizontalAlignment="Center" Padding="20,0,20,0" Margin="0,0,20,0"/>
    <optimumScheduler:LookUpCancelButton Grid.Row="1" Content="Cancel" HorizontalAlignment="Center" Padding="20,0,20,0"/>

我需要调整条目。我需要调整 OK 按钮。如果用户没有输入以下内容之一:患者、医生/治疗师、部门,那么我们希望禁用 OK 按钮或不允许输入。

在这里他们被定义。其中之一。我将如何编码它必须在主题中有一个条目

public static string FormatAppointmentFormCaption(bool allDay, string subject, bool readOnly)
{
    string format = allDay ? "Event - {0}" : "Appt Editor - {0}";
    string text = subject;
    if (string.IsNullOrEmpty(text))
         text = "Untitled";
    text = String.Format(CultureInfo.InvariantCulture, format, text);
    if (readOnly)
         text += " [Read only]";
    return text;
}
4

2 回答 2

1

我建议使用IDataErrorInfo接口并在属性上触发IsEnabled按钮的Validation.HasError属性以供您输入。

例如,您的 ViewModel 可能如下所示:

public class UserEntry: IDataErrorInfo
{
    public string UserType{get;set;}

    string IDataErrorInfo.this[string propertyName]
    {
        get
        {
            if(propertyName=="UserType")
            {
                // This is greatly simplified -- your validation may be different
                if(UserType != "Patient" || UserType != "Doctor" || UserType != "Department")
                {
                    return "Entry must be either Patient, Doctor, or Department.";
                }
            }
            return null;
        }
    }

    string IDataErrorInfo.Error
    {
        get
        {
            return null; // You can implement this if you like
        }
    }
}

您的 View 可能有一些类似于此的 XAML:

<TextBox Name="_userType"
         Text="{Binding UserType, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true}" />

<Button Command="{Binding OKCommand}"
        Name="OK">
  <Button.Style>
    <Style TargetType="Button">
      <Style.Triggers>
        <DataTrigger Binding="{Binding ElementName=_userType, Path=(Validation.HasError), Mode=OneWay}"
                      Value="False">
          <Setter Property="IsEnabled"
                  Value="True" />
        </DataTrigger>
        <DataTrigger Binding="{Binding ElementName=_userType, Path=(Validation.HasError), Mode=OneWay}"
                      Value="True">
          <Setter Property="IsEnabled"
                  Value="False" />
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </Button.Style>
</Button>
于 2013-10-03T21:57:21.153 回答
0

看看这个链接。当时对我很有帮助!

ICommand 实现

如果有任何机会您无法完成 using ICommand,请使用if语句并将元素IsEnabled属性设置为 false:

if(String.IsNullOrEmpty(Patient) || String.IsNullOrEmpty(Doctor) || String.IsNullOrEmpty(Therapist) || String.IsNullOrEmpty(DEpartment))
{
    yourElement.IsEnabled = false
}

假设PatientDoctor和是一个字符串属性(即 TextBox.Text、Label.Content 等等......)TherapistDEpartment

于 2013-10-03T21:21:53.023 回答