2012-05-15 67 views
3

我在ItemTemplate中有一些listView和userControl。此UserControl包含一些我需要驗證的文本框。一切正常,直到我啓用ListView的虛擬化。現在驗證僅適用於可見項目。如何驗證虛擬化的listview?

我該如何解決這個問題?

回答

1

由於UI虛擬化回收可視容器,它將重置它們,因此解決方案將手動綁定到用戶控件中的某些屬性,並在View Model中進行驗證。然後,當它未通過驗證時,將UserControl的邊框顏色和大小更改爲紅色和較粗的邊框。

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

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

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

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

OR

你可以有你的視圖模型實現IDataErrorInfo的,並使用該接口來定義的驗證規則

This網站有一個很好的例子。