0

I have a ListView that has children with text boxes. These text boxes have validation rules attached to them. It it possible to create some kind of binding that will disable the button when one of the text boxes isn't valid?

Here's a quick example:

<Window x:Class="wpf.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:validationRules="clr-namespace:ValidationRules" Title="MainWindow" Height="350" Width="525">
    <DockPanel>
        <ListView ItemsSource="{Binding ExampleCollection}">
            <ListView.View>
                <GridView AllowsColumnReorder="False">

                    <GridViewColumn Header="Example">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBox>
                                    <TextBox.Text>
                                        <Binding Path="Example" UpdateSourceTrigger="PropertyChanged">
                                            <Binding.ValidationRules>
                                                <validationRules:ByteValidationRule/>
                                            </Binding.ValidationRules>
                                        </Binding>
                                    </TextBox.Text>
                                </TextBox>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
        <Button DockPanel.Dock="Bottom">Save</Button>
    </DockPanel>
</Window>
LandonSchropp
  • 10,084
  • 22
  • 86
  • 149

1 Answers1

0

Using WPF Validation rules and disabling a 'Save' button

Community
  • 1
  • 1
pchajer
  • 1,584
  • 2
  • 13
  • 25
  • That looks promising, but I can't seem to figure out a way to bind to all of the TextBoxes in my ListView. Could you please provided a code example? – LandonSchropp Dec 01 '11 at 07:01