English 中文(简体)
WPF: How to use adorners for accreditation purpose?
原标题:WPF: How to use adorners for validation purposes?

Context:

I m 采用WPF 4, 包括两个<代码>Label 、一个<代码>TextB(用户名称)和一个<编码>PaswordBox。 这两个要素使用相同的风格/模板。

用户名必须贴在我的<编码>Username 上的财产,即示范类别,见观点-Model(代表其<代码>DataContext)。

The password updates the model using code-behind events (i.e.: OnPasswordChanged).

我的模型中还有两种特性,即我用户名和密码的真实状况:

  • UsernameIsValid
  • PasswordIsValid

这些财产由我的看法-模型和服务班更新。

< Question:

我如何为这些内容制定<条码>Adorner,并只在<条码>上显示。 用户名 财产是真实的?

我也希望尽可能通过在大使台上展示的文本(即显示案文的公告和一对文)

最佳回答

It s late so not providing code but will give you short answer.

  1. Setup Data Validation on the properties the text boxes are bound too (ValidationRule interface)
  2. Set default style on text box with adorner to what it should be when valid
  3. Set a style to what it should be when invalid using the DataError trigger.

下面是你如何使Xaml代码在风格上消失。

        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="BorderBrush" Value="Red"/>
                <Setter Property="BorderThickness" Value="1" />
                <Setter Property="Foreground" Value="Red" />
                <Setter 
                    Property="ToolTip" 
                    Value="{Binding RelativeSource={x:Static RelativeSource.Self},Path=(Validation.Errors)[0].ErrorContent}" />
            </Trigger>
        </Style.Triggers>
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签