2017-01-18 7 views
0

私はwpfでCheckedListboxを実装しようとしています。 5(私は5チェックボックスにのみテキストボックスを参照してくださいデバッグすることでCheckedListboxはテキストを表示しません

public class CheckedList : INotifyPropertyChanged 
    {private string _text; 
     public string SetText 
     { 
      get { return _text; } 
      set { _text = value; 
      OnPropertyChanged("SetText"); 
      } 
     } 

     private bool _checked; 
     public bool Checked 
     { 
      get { return _checked; } 
      set 
      { 
       _checked = value; 
       OnPropertyChanged("Checked"); 
      } 
     } 
     [field: NonSerialized] 
     public event PropertyChangedEventHandler PropertyChanged; 
     private void OnPropertyChanged(string propertyName) 
     { 
      PropertyChangedEventHandler handler = PropertyChanged; 
      if (handler != null) 
      { 
       handler(this, new PropertyChangedEventArgs(propertyName)); 
      } 

     } 
    } 


    class MigratorAdvancedMigrationOptionsViewModel : INotifyPropertyChanged 
    { 
     Migrator _Migrator { get; set; } 
     CloseClass _Close { get; set; } 
     public RelayCommand<IClosable> CloseWindowCommand { get; private set; } 
     public RelayCommand<IShowable> ShowWindowCommand { get; private set; } 
     public RelayCommand<IShowable> BackWindowCommand { get; private set; } 
     public string WindowTitle { get; private set; } 
     Window _window; 
     private RelayCommand<object> _setRequirements; 
     public ObservableCollection<string> List { get; set; } 
     public ObservableCollection<CheckedList> selectedList { get; set; } 


     public MigratorAdvancedMigrationOptionsViewModel(Migrator _migrator, CloseClass _Close) 
     { 
      this.ShowWindowCommand = new RelayCommand<IShowable>(this.ShowWindow); 
      this.BackWindowCommand = new RelayCommand<IShowable>(this.Back); 
      this._setRequirements = new RelayCommand<object>(Set_Requirements); 
      _onClosingCommand = new RelayCommand<object>(OnClosing_Command); 
      _Migrator = _migrator; 
      this._Close = _Close; 

      List = (ObservableCollection<string>)_migrator.GetTables(); 
      selectedList = new ObservableCollection<CheckedList>(); 
      CheckedList checkedList= new CheckedList(); 
      foreach (string item in List) 
      { 

       checkedList.SetText = item; 
       checkedList.Checked = false; 
       selectedList.Add(checkedList); 
      } 

     } 



     private RelayCommand<object> _onClosingCommand; 
     public ICommand OnClosingCommand 
     { 
      get { return _onClosingCommand; } 
     } 

     private void OnClosing_Command(object obj) 
     { 
      _Close.IsClosedFromButton = true; 
      _Close.CancelConfirmation(obj); 
     } 


     public ICommand SetRequirements 
     { 
      get { return _setRequirements; } 
     } 


     private void Set_Requirements(object obj) 
     { 

      _window = System.Windows.Application.Current.Windows[4]; 
      _Close.Set_Requirements(_window); 
     } 


     private void ShowWindow(IShowable window) 
     { 

     } 


     private void Back(object obj) 
     { 
      _Close.Back(3, 4); 
      _Migrator._windowState = SpaixDM.NetDesktop.Models.WindowState.options; 
     } 





     [field: NonSerialized] 
     public event PropertyChangedEventHandler PropertyChanged; 
     private void OnPropertyChanged(string propertyName) 
     { 
      PropertyChangedEventHandler handler = PropertyChanged; 
      if (handler != null) 
      { 
       handler(this, new PropertyChangedEventArgs(propertyName)); 
      } 

     } 
    } 

私は、チェックボックスで

<ListBox Grid.Row="3" Grid.Column="0" ItemsSource="{Binding selectedList}" > 
          <ListBox.ItemTemplate> 
           <DataTemplate> 
            <CheckBox Content="{Binding CheckedList.SetText}" IsChecked="{Binding CheckedList.Checked, Mode=TwoWay}"/> 

           </DataTemplate> 
          </ListBox.ItemTemplate> 
         </ListBox> 

をリストの項目を選択し、リストからそれを埋めるためにしたい、これが私のVMクラスでありますselectedListの項目)とそれ以上のものはありません。 私はそれはまた、あなたはCheckedListObservableCollectionあるselectedListListBoxを結合している

+0

あなたは何を見ますか?その不明確 –

+0

コンボボックスのコンセプト。私はテキストなしのコンボボックスから四角形しかありません – Bird75

答えて

0

を動作しません。また、この変化

public class CheckedList 
    { 
     public string Text { get; set; } 
     public bool Value { get; set; } 
    } 


    class MigratorAdvancedMigrationOptionsViewModel : INotifyPropertyChanged 
    { 
     Migrator _Migrator { get; set; } 
     CloseClass _Close { get; set; } 
     public RelayCommand<IClosable> CloseWindowCommand { get; private set; } 
     public RelayCommand<IShowable> ShowWindowCommand { get; private set; } 
     public RelayCommand<IShowable> BackWindowCommand { get; private set; } 
     public string WindowTitle { get; private set; } 
     Window _window; 
     private RelayCommand<object> _setRequirements; 
     public ObservableCollection<string> List { get; set; } 
     public ObservableCollection<CheckedList> selectedList { get; set; } 


     public MigratorAdvancedMigrationOptionsViewModel(Migrator _migrator, CloseClass _Close) 
     { 
      this.ShowWindowCommand = new RelayCommand<IShowable>(this.ShowWindow); 
      this.BackWindowCommand = new RelayCommand<IShowable>(this.Back); 
      this._setRequirements = new RelayCommand<object>(Set_Requirements); 
      _onClosingCommand = new RelayCommand<object>(OnClosing_Command); 
      _Migrator = _migrator; 
      this._Close = _Close; 

      List = (ObservableCollection<string>)_migrator.GetTables(); 
      selectedList = new ObservableCollection<CheckedList>(); 
      CheckedList checkedList= new CheckedList(); 
      foreach (string item in List) 
      { 
       checkedList.Text = item; 
       SetText = item; 
       checkedList.Value = false; 
       Checked = false; 
       selectedList.Add(checkedList); 
      } 

     } 

     private string _text; 
     public string SetText 
     { 
      get { return _text; } 
      set { _text = value; 
      OnPropertyChanged("SetText"); 
      } 
     } 

     private bool _checked; 
     public bool Checked 
     { 
      get { return _checked; } 
      set 
      { 
       _checked = value; 
       OnPropertyChanged("Checked"); 
      } 
     } 

      [field: NonSerialized] 
     public event PropertyChangedEventHandler PropertyChanged; 
     private void OnPropertyChanged(string propertyName) 
     { 
      PropertyChangedEventHandler handler = PropertyChanged; 
      if (handler != null) 
      { 
       handler(this, new PropertyChangedEventArgs(propertyName)); 
      } 

     } 
    } 

を試してみました。 SetTextだけにバインドする必要がある場合は、CheckBoxのコンテンツをCheckedList.SetTextにバインドしています。

<DataTemplate> 
    <CheckBox Content="{Binding SetText}" IsChecked="{Binding Value, Mode=TwoWay}"/> 
</DataTemplate> 

データテンプレートは、リスト内の各オブジェクトに表示するかを定義し、データのコンテキスト、すなわちCheckedListインスタンスそのオブジェクトに設定されます。 CheckedList.SetTextを置くことで、バインディングは存在しないCheckedListクラスのCheckedListプロパティを探します。

関連する問題