3

我在 ItemTemplate 中有一些带有 userControl 的 listView。此 UserControl 包含一些我需要验证的文本框。在我为 ListView 启用虚拟化之前,一切正常。现在验证仅适用于可见项目。

我该如何解决这个问题?

4

1 回答 1

1

Because the UI virtualization recycles the visual containers, it will reset them, so the solution would be to manually bind to the some properties in the user control, and do your validation in the View Model. Then when it doesn't pass validation change the border color and size of the UserControl to red and a thicker border.

<UserControl...>
  <Grid>
    <Border BorderThickness="{Binding Path=Border_Thickness_property}" BorderBrush="{Binding Path=Border_brush_color}">

    <!-- Put your textboxes and such here... -->

    </Border>
  </Grid>
</UserControl>

reference: http://www.codeproject.com/Articles/34405/WPF-Data-Virtualization

OR

You could have your View Model implement IDataErrorInfo and use that interface to define your validation rules

This site has a nice example.

于 2012-10-26T21:40:31.567 回答