WPF Error Provider

I look at the WPF components in the toolbar, but I can not find the error provider that was present in 2005/2008.

Is he recovered?

+3
source share
3 answers

ErrorProvider is a Winforms control. There is no equivalent in WPF. But you can still find in visual studio 2008 if you create a project of the forms of winnings.

Maybe you should take a look at this article in error checking in WPF . It has some useful tips and ideas on how to deal with verification.

+7
source

.NET 3.5 added WPF support for IDataErrorInfo: Data Validation in .NET 3.5 .

+4

, , , " -"

Simon P.Stevens, , , :

  • responseTemplate .
  • , ( , , ).
  • ( ) , , .

, MVVM :

TextBox BorderBrush ToolTip, / :

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}"/>

(LostFocus = 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");
                }
            }

Very useful when the rules are specific to the situation.

0
source

Source: https://habr.com/ru/post/1722326/


All Articles