2010-04-07 45 views
2

我有一個datagrid,其中有一些TextColumn和一個DataGridCheckBoxColumn。我將它與包含布爾值的itemsource進行綁定,我可以看到我的checkboxes或者通過布爾值檢查或不檢查在這一點上是否正確。如何在Silverlight 3的DataGridCheckBoxColumn中編輯布爾值

但是複選框單元格在ReadOnly中,即使我分配了IsReadOnly = False。我無法找到正確且乾淨的方式來啓用編輯。

我不需要數據驗證,但有理由能夠編輯和檢查這些複選框。

enter image description here

+0

的項目中的ItemsSource也可寫'Available'財產? xaml和代碼的簡短示例會有所幫助。 – AnthonyWJones 2010-04-07 10:52:31

回答

2

是綁定模式爲雙向的DataGridCheckBoxColumn?

此代碼適用於我。

<data:DataGrid Grid.Row="1" Width="600" MaxHeight="200" 
    GridLinesVisibility="Horizontal" 
    AutoGenerateColumns="False" VerticalScrollBarVisibility="Auto" 
    HorizontalScrollBarVisibility="Auto" 
    ItemsSource="{Binding Path=ProductPull.Items, Mode=OneWay}"> 
     <data:DataGrid.Columns> 
      <data:DataGridCheckBoxColumn Header="Select" 
       Binding="{Binding Path=IsSelected, Mode=TwoWay}" /> 

編輯

Silverlight Data Binding這裏是結合模式:

Direction of the Data Flow 
    -------------------------------------------------------------------------------- 

    Each binding has a Mode property, which determines 
how and when the data flows. Silverlight enables three types of bindings: 

    OneTime bindings update the target with the 
source data when the binding is created. 

    OneWay bindings update the target with the 
source data when the binding is created and anytime the data changes. 
This is the default mode. 

    TwoWay bindings update both the target and the 
source when either changes. Alternately, you can disable 
automatic source updates and update the source only at times of your choosing. 

    In order for automatic target updates to occur, 
the source object must implement the INotifyPropertyChanged interface, 
as described in the next section. 
+0

模式有什麼區別? – Polo 2010-04-08 08:51:29

+1

@Polo - 我已經修改了我的答案,以包含綁定模式。 – DaveB 2010-04-08 15:22:24