当ListView项无效时禁用按钮

时间:2011-11-29 09:50:05

标签: wpf xaml

我有一个ListView有孩子的文本框。这些文本框附有验证规则。它可以创建某种绑定,当其中一个文本框无效时将禁用该按钮吗?

这是一个简单的例子:

<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>

1 个答案:

答案 0 :(得分:0)