I am looking at WPF componenents in the toolbox but I cannot find the error provider that is present in 2005/2008.
Is it removed?
I am looking at WPF componenents in the toolbox but I cannot find the error provider that is present in 2005/2008.
Is it removed?
the ErrorProvider is a Winforms control. There is no equivalent in WPF. But you will still be able to find in in visual studio 2008 if you create a win forms project.
You might want to take a look at this article on error validation in WPF. It has some useful suggestions and ideas for how to handle validation.
.NET 3.5 added WPF support for IDataErrorInfo: Data validation in .NET 3.5.
First excuse me for commenting a such old discussion, but this could help as I had exactly the same question, and Simon's link helped me to "begin with something"
I could test Simon P.Stevens tutorial, but honestly I didn't like it that much :
I think using MVVM is very well adapted to manage any situation :
I set my TextBox, with a BorderBrush , and ToolTip, regarding my conditions I will Hide/Display ToolTip and color border :
XAML :
<TextBox x:Name="tbName" Grid.Column="1" Grid.Row="0" Margin="3" LostFocus="tbName_LostFocus" BorderBrush="{Binding BordertbName}"
Text="{Binding MonRepere.Nom}" ToolTipService.ToolTip="{Binding ErrorName}" ToolTipService.IsEnabled="{Binding ToolTipNameEnable}"/>
Code Behind (LostFocus = Leave for whom used to WindowsForm) :
private void tbName_LostFocus(object sender, RoutedEventArgs e)
{
if(tbName.Text=="")
{
this.mv.ErrorName = Properties.Resources.ErrorEmpty;
}
else
{
mv.ErrorName = "";
}
}
Then ViewModel :
private string errorName;
public string ErrorName
{
get { return errorName; }
set
{
errorName = value;
if (value == "")
{
ToolTipNameEnable = false;
BordertbName = Brushes.Gray;
}
else
{
ToolTipNameEnable = true;
BordertbName = Brushes.Red;
}
this.NotifyPropertyChanged("ErrorName");
}
}
private Brush bordertbName;
public Brush BordertbName
{
get { return bordertbName; }
set
{
bordertbName = value;
this.NotifyPropertyChanged("BordertbName");
}
}
private bool toolTipNameEnable;
public bool ToolTipNameEnable
{
get { return toolTipNameEnable; }
set
{
toolTipNameEnable = value;
this.NotifyPropertyChanged("ToolTipNameEnable");
}
}
Just very useful when rules are specific regarding the situation.
© 2022 - 2024 — McMap. All rights reserved.