KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've adopted what appears to be the standard way of validating textboxes in WPF using the IDataErrorInfo interface and styles as shown below. However, how can I disable the Save button when the page becomes invalid? Is this done somehow through triggers? Default Public ReadOnly Property Item(ByVal propertyName As String) As String Implements IDataErrorInfo.Item Get Dim valid As Boolean = True If propertyName = "IncidentCategory" Then valid = True If Len(IncidentCategory) = 0 Then valid = False End If If Not valid Then Return "Incident category is required" End If End If Return Nothing End Get End Property <Style TargetType="{x:Type TextBox}"> <Setter Property="Margin" Value="3" /> <Setter Property="Height" Value="23" /> <Setter Property="HorizontalAlignment" Value="Left" /> <Setter Property="Validation.ErrorTemplate"> <Setter.Value> <ControlTemplate> <DockPanel LastChildFill="True"> <Border BorderBrush="Red" BorderThickness="1"> <AdornedElementPlaceholder Name="MyAdorner" /> </Border> </DockPanel> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" /> </Trigger> </Style.Triggers> </Style>
Tags (comma-separated)
Save Edits
Cancel