2012-09-27 41 views
1

我有一個WPF DataGrid。其中有一列包含編輯按鈕,這樣如何啓用或禁用數據網格progrmaticaly的一些按鈕例如如何禁用wpf數據網格的某些按鈕

<DataGrid AutoGenerateColumns="True" Height="80" Margin="2,-4,8,0" Name="grdQHDRShowAll" VerticalAlignment="Top" ItemsSource="{Binding}" IsReadOnly="True" SelectionChanged="grdQHDRShowAll_SelectionChanged"> 
             <DataGrid.Columns> 

              <DataGridTemplateColumn> 
               <DataGridTemplateColumn.CellTemplate> 
                <DataTemplate> 
                 <Button Click="Qhdr_CreateOrder_Click" CommandParameter="{Binding Path=QuoteNo}" >Create Order</Button> 
                </DataTemplate> 
               </DataGridTemplateColumn.CellTemplate> 
              </DataGridTemplateColumn> 
             </DataGrid.Columns> 
            </DataGrid> 

上面的代碼具有帶有按鈕的列,所以我想知道如何以行禁用某些按鈕取決於對其他列的數據如第二列的真值和假值,如果第二列第一行有數據true則第一列第一行按鈕應該是使能手段取決於任何列其他列如何eable /禁用datagrid的按鈕?

回答

1

如果你使用的MVVM模式,你可以在按鈕的IsEnabled屬性綁定到你的虛擬機的布爾屬性,或者你使用一個轉換器將其轉換爲一個boolean類型:

<Button IsEnabled="{Binding Path=BoolProp}"/> 

如果沒有,你可以使用elementbinding其綁定到一個元素:

<Button IsEnabled="{Binding ElementName=CellName, Path=BoolProp}"/> 
+0

Gr8謝謝你... – Raj

0
<Button Content="Approve" VerticalAlignment="Center" Height="23" Width="90" FontWeight="Bold" Command="{Binding ApprovedCommand}" Margin="5,0,0,0" IsEnabled="{Binding IsEnabled,Mode=TwoWay}"/> 

在MVVM創建一個屬性,使的IsEnabled真或假條件

+0

你確定這個模式應該是'TwoWay'嗎?當使用與TwoWay相等的模式綁定時,我會期待一個'InvalidOperationException'。 –