回答編集履歴
4
111
answer
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
こんな感じでしょうか
|
2
|
-
CollectionViewSource.Filterを使います
|
2
|
+
CollectionViewSource.View.Filterを使います
|
3
3
|
|
4
4
|
```XAML
|
5
5
|
<Window x:Class="WpfApplication1.MainWindow"
|
3
コメント
answer
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
こんな感じでしょうか
|
2
|
+
CollectionViewSource.Filterを使います
|
2
3
|
|
3
4
|
```XAML
|
4
5
|
<Window x:Class="WpfApplication1.MainWindow"
|
2
アイテム
answer
CHANGED
@@ -1,2 +1,61 @@
|
|
1
|
-
こ
|
1
|
+
こんな感じでしょうか
|
2
|
+
|
3
|
+
```XAML
|
4
|
+
<Window x:Class="WpfApplication1.MainWindow"
|
5
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
6
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
7
|
+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
8
|
+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
9
|
+
xmlns:local="clr-namespace:WpfApplication30"
|
10
|
+
mc:Ignorable="d"
|
11
|
+
Title="MainWindow" Height="350" Width="525">
|
12
|
+
<Grid>
|
13
|
+
<ComboBox x:Name="comboBox" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" DisplayMemberPath="Name" SelectedValuePath="Id"/>
|
14
|
+
</Grid>
|
15
|
+
</Window>
|
16
|
+
```
|
17
|
+
|
18
|
+
```C#
|
19
|
+
using System.Collections.ObjectModel;
|
20
|
+
using System.Windows;
|
21
|
+
using System.Windows.Data;
|
22
|
+
|
23
|
+
namespace WpfApplication1
|
24
|
+
{
|
25
|
+
/// <summary>
|
26
|
+
/// MainWindow.xaml の相互作用ロジック
|
27
|
+
/// </summary>
|
28
|
+
public partial class MainWindow : Window
|
29
|
+
{
|
30
|
+
private class Hoge
|
31
|
+
{
|
32
|
+
public int ID { get; set; }
|
33
|
+
public string Name { get; set; }
|
34
|
+
}
|
35
|
+
|
36
|
+
private ObservableCollection<Hoge> HogeItems { get; set; }
|
37
|
+
private CollectionViewSource HogeViewSource { get; set; }
|
38
|
+
|
39
|
+
public MainWindow()
|
40
|
+
{
|
41
|
+
InitializeComponent();
|
42
|
+
|
43
|
+
this.HogeItems = new ObservableCollection<Hoge>();
|
44
|
+
this.HogeViewSource = new CollectionViewSource() { Source = this.HogeItems };
|
2
|
-
comboBox.
|
45
|
+
this.comboBox.ItemsSource = this.HogeViewSource.View;
|
46
|
+
|
47
|
+
this.HogeItems.Add(new Hoge { ID = 1, Name = "A" });
|
48
|
+
this.HogeItems.Add(new Hoge { ID = 2, Name = "B" });
|
49
|
+
this.HogeItems.Add(new Hoge { ID = 3, Name = "C" });
|
50
|
+
this.HogeItems.Add(new Hoge { ID = 4, Name = "D" });
|
51
|
+
this.HogeItems.Add(new Hoge { ID = 5, Name = "E" });
|
52
|
+
|
53
|
+
this.HogeViewSource.View.Filter = (n) =>
|
54
|
+
{
|
55
|
+
var item = n as Hoge;
|
56
|
+
return item.ID > 2;
|
57
|
+
};
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
```
|
1
非表示
answer
CHANGED
@@ -1,65 +1,2 @@
|
|
1
|
-
こ
|
1
|
+
これでしょうか
|
2
|
-
CollectionViewSourceを使います
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
```XAML
|
7
|
-
<Window x:Class="WpfApplication1.MainWindow"
|
8
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
9
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
10
|
-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
11
|
-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
12
|
-
xmlns:local="clr-namespace:WpfApplication30"
|
13
|
-
mc:Ignorable="d"
|
14
|
-
Title="MainWindow" Height="350" Width="525">
|
15
|
-
<Grid>
|
16
|
-
<ComboBox x:Name="comboBox" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" DisplayMemberPath="Name" SelectedValuePath="Id"/>
|
17
|
-
</Grid>
|
18
|
-
</Window>
|
19
|
-
```
|
20
|
-
|
21
|
-
```C#
|
22
|
-
using System.Collections.ObjectModel;
|
23
|
-
using System.Windows;
|
24
|
-
using System.Windows.Data;
|
25
|
-
|
26
|
-
namespace WpfApplication1
|
27
|
-
{
|
28
|
-
/// <summary>
|
29
|
-
/// MainWindow.xaml の相互作用ロジック
|
30
|
-
/// </summary>
|
31
|
-
public partial class MainWindow : Window
|
32
|
-
{
|
33
|
-
private class Hoge
|
34
|
-
{
|
35
|
-
public int ID { get; set; }
|
36
|
-
public string Name { get; set; }
|
37
|
-
}
|
38
|
-
|
39
|
-
private ObservableCollection<Hoge> HogeItems { get; set; }
|
40
|
-
private CollectionViewSource HogeViewSource { get; set; }
|
41
|
-
|
42
|
-
public MainWindow()
|
43
|
-
{
|
44
|
-
InitializeComponent();
|
45
|
-
|
46
|
-
this.HogeItems = new ObservableCollection<Hoge>();
|
47
|
-
this.HogeViewSource = new CollectionViewSource() { Source = this.HogeItems };
|
48
|
-
|
2
|
+
comboBox.Visibility = Visibility.Collapsed;
|
49
|
-
|
50
|
-
this.HogeItems.Add(new Hoge { ID = 1, Name = "A" });
|
51
|
-
this.HogeItems.Add(new Hoge { ID = 2, Name = "B" });
|
52
|
-
this.HogeItems.Add(new Hoge { ID = 3, Name = "C" });
|
53
|
-
this.HogeItems.Add(new Hoge { ID = 4, Name = "D" });
|
54
|
-
this.HogeItems.Add(new Hoge { ID = 5, Name = "E" });
|
55
|
-
|
56
|
-
this.HogeViewSource.View.Filter = (n) =>
|
57
|
-
{
|
58
|
-
var item = n as Hoge;
|
59
|
-
return item.ID > 2;
|
60
|
-
};
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
```
|