teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

ファイル名を修正いたしました。

2019/07/15 11:20

投稿

heroherohero
heroherohero

スコア38

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,5 @@
1
+ ※すみません、最初に、記載していたソースのファイル名などを、ほかの方が分かりやすいように、置き換えていたのですが、添付している画像のエラーとの差異があったため、現状のファイル名をそのまま記載いたします。どうぞ、よろしくお願いいたします。
2
+
1
3
  お世話になっております。
2
4
 
3
5
  Prism 6.3(MVVMパターン)の開発環境で、UWPのアプリを開発しております。
@@ -21,6 +23,17 @@
21
23
 
22
24
  - MainViewModel.cs(一部抜粋)
23
25
  ```C#
26
+ using System;
27
+ using System.Collections.Generic;
28
+ using System.IO;
29
+ using Prism.Windows.Mvvm;
30
+ using Prism.Windows.Navigation;
31
+ using Windows.ApplicationModel.Resources;
32
+ using Windows.Storage;
33
+ using Windows.Storage.Pickers;
34
+ using Windows.UI.Xaml;
35
+ using Windows.UI.Xaml.Controls;
36
+
24
37
  namespace LearningAlbum.ViewModels
25
38
  {
26
39
  public class Photo
@@ -30,11 +43,11 @@
30
43
  public string ReflectionTitle { get; set; }
31
44
  }
32
45
 
33
- public class MainViewModel : ViewModelBase
46
+ public class PhotoListViewModel : ViewModelBase
34
47
  {
35
48
  public List<Photo> _PhotoList { get; set; }
36
49
 
37
- public MainViewModel ()
50
+ public PhotoListViewModel()
38
51
  {
39
52
  this._PhotoList = new List<Photo>
40
53
  {
@@ -46,29 +59,28 @@
46
59
  }
47
60
  ```
48
61
 
49
- - MainPage.xaml(一部抜粋)
62
+ - PhotoListPage.xaml(一部抜粋)
50
63
  ```C#
51
64
  <Page
52
65
  x:Class="LearningAlbum.Views.PhotoListPage"
53
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
66
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
54
67
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
68
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
56
69
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
57
70
  xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
58
- xmlns:local="using:LearningAlbum.ViewModels"
71
+ xmlns:local="using:LearningAlbum.ViewModels"
59
72
  Style="{StaticResource PageStyle}"
60
73
  xmlns:prismMvvm="using:Prism.Windows.Mvvm"
61
74
  prismMvvm:ViewModelLocator.AutoWireViewModel="True"
62
75
  mc:Ignorable="d">
63
76
 
64
- <controls:AdaptiveGridView Name="SuggestionGridView"
77
+ <controls:AdaptiveGridView Name="SuggestionGridView"
65
78
  Style="{StaticResource MainGridView}"
66
79
  SelectionChanged="SelectionChanged"
67
- ItemsSource="{x:Bind ViewModel._PhotoList, Mode=OneWay}"
80
+ ItemsSource="{x:Bind ViewModel._PhotoList}"
68
81
  StretchContentForSingleRow="False" >
69
82
  <controls:AdaptiveGridView.ItemTemplate>
70
- <!--<DataTemplate x:DataType="local:Photo">-->
71
- <DataTemplate x:DataType="local:Photo">
83
+ <DataTemplate x:DataType="local:Photo" >
72
84
  <StackPanel Margin="4" MaxWidth="276">
73
85
  <Grid>
74
86
  <Image Source="{x:Bind FilePath}" Style="{StaticResource GridViewImage}"/>
@@ -88,7 +100,7 @@
88
100
  </controls:AdaptiveGridView>
89
101
  ```
90
102
 
91
- MainPage.xaml.cs(コードビハインド)
103
+ PhotoListPage.xaml.cs(コードビハインド)
92
104
  ```C#
93
105
  using System;
94
106
 
@@ -98,11 +110,11 @@
98
110
 
99
111
  namespace LearningAlbum.Views
100
112
  {
101
- public sealed partial class MainPage: Page
113
+ public sealed partial class PhotoListPage : Page
102
114
  {
103
- private MainViewModel ViewModel => DataContext as MainViewModel;
115
+ private PhotoListViewModel ViewModel => DataContext as PhotoListViewModel;
104
116
 
105
- public MainPage()
117
+ public PhotoListPage()
106
118
  {
107
119
  InitializeComponent();
108
120
  }

1

コードビハインドのソースコードを追加いたしました。

2019/07/15 11:20

投稿

heroherohero
heroherohero

スコア38

title CHANGED
File without changes
body CHANGED
@@ -46,7 +46,7 @@
46
46
  }
47
47
  ```
48
48
 
49
- - リストMainPage.xaml(一部抜粋)
49
+ - MainPage.xaml(一部抜粋)
50
50
  ```C#
51
51
  <Page
52
52
  x:Class="LearningAlbum.Views.PhotoListPage"
@@ -86,4 +86,26 @@
86
86
  </DataTemplate>
87
87
  </controls:AdaptiveGridView.ItemTemplate>
88
88
  </controls:AdaptiveGridView>
89
+ ```
90
+
91
+ ◆MainPage.xaml.cs(コードビハインド)
92
+ ```C#
93
+ using System;
94
+
95
+ using LearningAlbum.ViewModels;
96
+
97
+ using Windows.UI.Xaml.Controls;
98
+
99
+ namespace LearningAlbum.Views
100
+ {
101
+ public sealed partial class MainPage: Page
102
+ {
103
+ private MainViewModel ViewModel => DataContext as MainViewModel;
104
+
105
+ public MainPage()
106
+ {
107
+ InitializeComponent();
108
+ }
109
+ }
110
+ }
89
111
  ```