views:

139

answers:

2

I can't figure this guy out / in desperate need of assistance.

I have an ItemsControl and a DataTemplate as the ItemTemplate

i.e.

<DataTemplate>
    <StackPanel>
       <TextBox Text={Binding Prop1}/>
       <TextBox Text={Binding Prop2}/>
    </StackPanel>
</DataTemplate>

I have seen plenty of examples for applying validation to the target of an individual binding (i.e. just validating each textbox separately). I'd like to have a visual change to the whole DataTemplate if there is ANYTHING wrong (either Prop1 OR Prop2), using an <AdornedelementPlaceholder/>, as I've seen in many examples.

Essenetially, is there a way to show an error if ANY item in the object that represents my DataContext of the DataTemplate has a problem?

A: 

Try setting a BindingGroup on a StackPanel like below and set individual validation rules on each of your TextBoxes. I haven't actually tried this but it should work.

<StackPanel>
    <StackPanel.BindingGroup>
         <BindingGroup />
    </StackPanel.BindingGroup>

    <TextBox Text={Binding Prop1}/>
    <TextBox Text={Binding Prop2}/>
</StackPanel>
wpfwannabe
A: 

You could define custom ErrorTemplates to both bindings, which define the StackPanel as Validation.ValidationAdornerSite. This way the StackPanel can be adorned instead of the textboxes, whenever an error is detected.

See this link for more details: Vincent Sibal about validation with ValidationAdornerSite

Simpzon