English 中文(简体)
数据网检查箱自动化
原标题:Data grid checkbox automation
  • 时间:2009-09-29 17:33:46
  •  标签:

我有一个带有检查箱的数据网。 当我点上了囚室时,我想在我选择了装有检查箱的囚室时自动检查。 我们现在要做的是,我需要选择在检查箱上点击的囚室,这对我们来说是很不舒服的。

<dg:DataGrid Name="GridUsureOperation" Margin="10,444,82,6" ItemsSource="{Binding}" Style="{StaticResource GridMenu}" SelectionMode="Single" SelectionUnit="Cell">
    <dg:DataGrid.Columns>
        <dg:DataGridTextColumn Header="Opération" Width="*" MinWidth="60" 
                               Binding="{Binding Operation.DescOperation}" 
                               IsReadOnly="True" />
        <dg:DataGridTextColumn Header="Dernière maintenance" Width="SizeToHeader" MinWidth="50"
                               Binding="{Binding DateDerniereMaintenance, StringFormat=yyyy-MM-dd}" 
                               IsReadOnly="True"/>
        <dg:DataGridTextColumn Header="Usure dernière maintenance" Width="SizeToHeader" MinWidth="50"
                               Binding="{Binding UsureDerniereOperation}" 
                               IsReadOnly="True"/>
        <dg:DataGridTextColumn Header="Fréquence(usure)" Width="SizeToHeader" MinWidth="50"
                               Binding="{Binding QteUsure}" 
                               IsReadOnly="True"/>
        <dg:DataGridTextColumn Header="Unité" Width="SizeToHeader" MinWidth="50"
                               Binding="{Binding TypeUsure.Description}" 
                               IsReadOnly="True"/>
        <dg:DataGridCheckBoxColumn Header="Forcer?" Width="SizeToHeader" MinWidth="50"
                               Binding="{Binding AfficherMaintenance}"                                         
                               IsReadOnly="False">

        </dg:DataGridCheckBoxColumn>
    </dg:DataGrid.Columns>
</dg:DataGrid>
最佳回答

我不喜欢使用数据GridCheckBoxColumn,因为它需要重点,然后才能与检查箱互动。 因此,我把一个 Check子放在一个模板栏内,你只需要一个点击变化状态。

<dg:DataGridTemplateColumn Width="SizeToHeader">
    <dg:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding Path=Selected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="2,0,2,0" />
        </DataTemplate>
    </dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>

但是,如果你真的想要检查箱在牢房任何地方(而不仅仅是在检查箱里)点击时改变状态,那么你可以使用以下代码,使检查局的监控能够覆盖到牢房的整个面积。

<dg:DataGridTemplateColumn Width="SizeToHeader">
    <dg:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding Path=Selected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="2,0,2,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
        </DataTemplate>
    </dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>

UPDATE I haven t done WPF dev in quite a while. I was having an issue using this solution now that the DataGrid is baked into the WPF libraries and you don t need the toolkit anymore. The checkbox did not want to update the backing property as previously written, so I have added a more complete binding statement that does seem to work.

问题回答

暂无回答




相关问题
热门标签