Missing an IsValid Property

Topics: Validation Application Block
Jul 3, 2012 at 3:55 PM



For my WPF progam I'm using Enterprise Library validation. Application is designed in MVVM. And to enable/disabling areas and controls I'm missing an IsValid property .

Here are 2 properties from my model:




[NotNullValidator(MessageTemplate = <Button
Command="{Binding GetCashOrder}"
CommandParameter="5"
Content="Münzen (umgelaufen)"
HorizontalAlignment="Left"
Margin="5,5,0,0"
Name="btnAddCoinsPortion"
VerticalAlignment="Top"
Width="220"
/>"Validating Error")]
public string BuyerGLN
{
get
{
return buyerGLN;
}
set
{
SetProperty(ref this.buyerGLN, value);
}
}

[NotNullValidator(MessageTemplate = "Validating Error")]
public string TourNumber
{
get
{
return tourNumber;
}
set
{
SetProperty(ref this.tourNumber, value);
}
}

And the XAML code from the view:

<ComboBox
HorizontalAlignment="Stretch"
Margin="5,5,5,10"
Name="cboTourNumber"
VerticalAlignment="Top"

ItemsSource="{Binding TourNumbers}"
DisplayMemberPath="TourID"
SelectedValuePath="TourID"
SelectedValue="{Binding myObject.TourNumber, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"
IsEditable="False" />
<ComboBox
Margin="5,10,5,10"
Name="cboRegister"
VerticalAlignment="Top"
HorizontalAlignment="Stretch"
ItemsSource="{Binding Register}"
DisplayMemberPath="Name"
SelectedValuePath="GLN"
SelectedValue="{Binding myObject.BuyerGLN, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"
IsEditable="False" >

How can I now disable/enable Button regarding to validation result
(should be enabled if myObject is valid,
vice versa disabled if myObject is invalid)?

XAML Code for button
<Button
Command="{Binding ExecCommand}"
CommandParameter="5"
Content="ExecCommand"
HorizontalAlignment="Left"
Margin="5,5,0,0"
Name="btnExecCommand"
VerticalAlignment="Top"
 Width="220"

IsEnabled="???"
/>

 

Regards

Volker

 

Jul 6, 2012 at 4:38 AM
Edited Jul 6, 2012 at 5:50 PM

From what I've seen a common way is to do this programmatically in code.  This answer at StackOverflow seems to be a common approach.  Are you using RelayCommand?  

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Jul 18, 2012 at 2:27 PM

This is what I'm looking for!

Thx

Volker