質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

MVVM

MVVM(Model View ViewModel)は構築上のデザインパターンで、表現ロジック(ViewModel)によってデータ(Model)からページ(View)を分離させます。

Q&A

1回答

836閲覧

DataGridでチェックボスと行の選択状態(フォーカス)を連動させたリストを作りたい

KakedasiKozo

総合スコア4

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

MVVM

MVVM(Model View ViewModel)は構築上のデザインパターンで、表現ロジック(ViewModel)によってデータ(Model)からページ(View)を分離させます。

0グッド

0クリップ

投稿2019/09/24 08:02

前提・実現したいこと

C#+Prism+ReactivePropertyでチェックボックスと行の選択状態が連動したリストを作りたいのです。(Gmailの受信リストの様な動き)

前提条件:としてMVVMパターンで、コードビハインドに何も書かずに実装したい。

ですが、実現方法が浮かびません。
「こうしたら実現できる」など方針や、ヒントなどがあれば教えていただきたいです。よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

Prism も ReactiveProperty も使っていません。
とりあえず新しいプロジェクトを作ってこれをそのまま試してください。
そして意図通りでない部分があれば既存のプロジェクトに合わせて自分で修正してください。

MainWindow.xaml

XAML

1<Window x:Class="WpfApp1.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:local="clr-namespace:WpfApp1" 7 mc:Ignorable="d" 8 Title="MainWindow" Height="450" Width="800"> 9 <Window.DataContext> 10 <local:MainViewModel/> 11 </Window.DataContext> 12 <Grid> 13 <DataGrid ItemsSource="{Binding Items}" SelectionMode="Extended"> 14 <DataGrid.ItemContainerStyle> 15 <Style TargetType="{x:Type DataGridRow}"> 16 <Setter Property="IsSelected" Value="{Binding IsChecked}"/> 17 </Style> 18 </DataGrid.ItemContainerStyle> 19 </DataGrid> 20 </Grid> 21</Window>

MainViewModel.cs

C#

1using System; 2using System.Collections.Generic; 3using System.Collections.ObjectModel; 4using System.ComponentModel; 5using System.Globalization; 6using System.Linq; 7using System.Runtime.CompilerServices; 8using System.Text; 9using System.Threading.Tasks; 10using System.Windows.Data; 11using System.Windows.Media; 12 13namespace WpfApp1 14{ 15 public class BindableBase : INotifyPropertyChanged 16 { 17 #region INotifyPropertyChanged 18 public event PropertyChangedEventHandler PropertyChanged; 19 protected virtual void OnPropertyChanged(string propertyName) 20 { 21 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 22 } 23 protected bool SetProperty<T>(ref T field, T value, [CallerMemberName]string propertyName = null) 24 { 25 if (EqualityComparer<T>.Default.Equals(field, value)) return false; 26 field = value; 27 OnPropertyChanged(propertyName); 28 return true; 29 } 30 #endregion 31 } 32 33 public class Item : BindableBase 34 { 35 private bool isChecked; 36 public bool IsChecked 37 { 38 get => isChecked; 39 set => SetProperty(ref isChecked, value); 40 } 41 42 private string text; 43 public string Text 44 { 45 get => text; 46 set => SetProperty(ref text, value); 47 } 48 } 49 50 public class MainViewModel : BindableBase 51 { 52 public MainViewModel() 53 { 54 Items = new ObservableCollection<Item>() 55 { 56 new Item() { Text = "Alice" }, 57 new Item() { Text = "Bob" }, 58 new Item() { Text = "Charley" }, 59 }; 60 } 61 62 public ObservableCollection<Item> Items { get; } 63 } 64}

投稿2019/09/24 09:58

編集2019/09/24 10:15
Zuishin

総合スコア28662

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問