WPF DataValidation on a DataTemplate object in an ItemsControl

Posted by Matt H. on Stack Overflow See other posts from Stack Overflow or by Matt H.
Published on 2010-03-27T21:59:04Z Indexed on 2010/03/27 22:03 UTC
Read the original article Hit count: 450

Filed under:
|
|

I have two datatemplates, both very similar... here is one of them:

<DataTemplate x:Key="HeadingTemplate">
<Grid x:Name="mainHeadingGrid" Margin="5,5,30,0" HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

        <TextBlock Grid.Column="1" Margin="30,3,10,0" Foreground="Black" FontWeight="Bold"
                       HorizontalAlignment="Left" TextWrapping="Wrap">
            <TextBlock.Text>
                <MultiBinding Converter="{StaticResource myHeadingConverter}" 
                                     ConverterParameter="getRNHeadingTitle" Mode="TwoWay">
                    <Binding Path="num"/>
                    <Binding Path="name"/>
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>

<TextBox Grid.Column="1" Text="{Binding Path=moreInfo}"/>
        </Grid>
</DataTemplate>

I use an selector in my ItemsControl to choose between the two, based on the object it is bound to.

I want to use validation to check through all of the properties and put a big exclamation point in front of the whole datatemplate as it is displayed in the itemscontrol.

how do I do this? All of the examples I've found explain how to set a ValidationRule on a specific control in the datatemplate, in that control's binding. I want to apply my validation rule to the entire template...

Help! :)

© Stack Overflow or respective owner

Related posts about wpf

Related posts about datatemplate