2011-08-02 16 views
4

私はWPFアプリケーションでMVVMフレームワークとしてCaliburn Microを使用します。私はちょっと問題がありませんどのようにすべてのチェックボックスをDataGridコントロールで選択します。すべてのデータグリッド行にはチェックボックスがあります。ビューモデルのデータグリッド行のすべてのチェックボックスを選択

私はListのdatagridプロパティタイプにバインドします。

モデル:

public class Bill : INotifyPropertyChanged 
{ 

    public string CellPhoneNo 
    { 
     get { return _cellPhoneNo; } 
     set 
     { 
      _cellPhoneNo = value; 
      NotifyPropertyChanged("CellPhoneNo"); 
     } 
    } 

    public bool IsSelected 
    { 
     get { return _isSelected; } 
     set 
     { 
      _isSelected = value; 
      NotifyPropertyChanged("IsSelected"); 
     } 
    } 

のViewModel:

public IList<Bill> TmobileBill 
    { 
     get 
     { 
      return _tmobileBill; 
     } 
     set 
     { 
      _tmobileBill = value; 
      NotifyOfPropertyChange(()=>TmobileBill); 
     } 
    } 

ビュー:私はクラスビルからIsSelected checboxのプロパティにisCheckedプロパティにバインドdatragrid行のためのDataTemplateで

<Controls:DataGrid ItemsSource="{Binding Path= TmobileBill, 
               Mode=OneWay, 
               UpdateSourceTrigger=PropertyChanged}" 
         Style="{StaticResource FinalBillsView_CallsDataGrid}" 
         Grid.Row="0" 
         CanUserResizeRows="False"> 

     <Controls:DataGrid.RowHeaderTemplate> 
      <DataTemplate> 
       <Grid> 
        <CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay, 
           RelativeSource={RelativeSource FindAncestor, 
           AncestorType={x:Type Controls:DataGridRow}}}"/> 
       </Grid> 
      </DataTemplate> 
     </Controls:DataGrid.RowHeaderTemplate> 

     <Controls:DataGrid.Columns> 

      <Controls:DataGridTextColumn IsReadOnly="True" 
              CellStyle="{StaticResource FinalBillsView_DataGrid_CellStyle}" 
              Binding="{Binding Path=CellPhoneNo}" 
              HeaderStyle="{StaticResource FinalBillsView_DataGridColHeaderStyle}" 
              Header="Cell phone No"/> 
     </Controls:DataGrid.Columns> 
    </Controls:DataGrid> 

リスト内のすべての項目について、プロパティIsSelectedをtrueに設定すると問題が発生します。

  foreach (var row in TmobileBill) 
      { 
       row.IsSelected = true; 
      } 

[表示]のチェックボックスはチェックされていません。問題の根は何ですか?

ありがとうございます。

+0

どのタイプのコントロールを使用していますか? (Datagrid) –

答えて

0
  1. デバッグの目的で<CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"/>

を結合簡単な使用してみてくださいObservableCollection<Bill>

  • IList<Bill>を変更しようと、実際にRowItemに結合するかを確認するチェックボックスの次のコントロールと一緒に定義します。

    <TextBlock Text="{Binding}"></TextBlock> 
    
  • 関連する問題