前提・実現したいこと
UWP初心者です。
ValidatableBindableBaseを継承したMainPageViewModelのMessageというプロパティにDataAnnotationsの検証用属性をつけて、View側で検証結果をBindして表示させたいです。
該当のソースコード
C#
1// MainPageViewModel.cs 2using Prism.Windows.Validation; 3using System.ComponentModel.DataAnnotations; 4 5namespace ValidatableBindableBaseApp.ViewModels 6{ 7 public class MainPageViewModel : ValidatableBindableBase 8 { 9 private string message; 10 11 [Required(ErrorMessage ="Required")] 12 public string Message 13 { 14 get { return this.message; } 15 set { this.SetProperty(ref this.message, value); } 16 } 17 18 } 19} 20// MainPage.xaml 21<Page 22 x:Class="ValidatableBindableBaseApp.Views.MainPage" 23 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 24 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 25 xmlns:local="using:ValidatableBindableBaseApp.Views" 26 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 27 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 28 xmlns:Mvvm="using:Prism.Windows.Mvvm" 29 Mvvm:ViewModelLocator.AutoWireViewModel="True" 30 mc:Ignorable="d" 31 Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 32 33 <StackPanel> 34 <TextBox Text="{x:Bind ViewModel.Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> 35 <TextBlock Text="{x:Bind ViewModel.Errors.Errors, Mode=OneWay}"/> 36 </StackPanel> 37</Page> 38 39// MainPage.xaml.cs 40using ValidatableBindableBaseApp.ViewModels; 41using Windows.UI.Xaml.Controls; 42 43// 空白ページの項目テンプレートについては、https://go.microsoft.com/fwlink/?LinkId=234238 を参照してください 44 45namespace ValidatableBindableBaseApp.Views 46{ 47 /// <summary> 48 /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。 49 /// </summary> 50 public sealed partial class MainPage : Page 51 { 52 public MainPageViewModel ViewModel => this.DataContext as MainPageViewModel; 53 public MainPage() 54 { 55 this.InitializeComponent(); 56 } 57 } 58}
###試したこと
ViewModel.Errors.Errorsだと、System.Collections.Generic.Dictionary2[System.String.System.Collections.ObjectModel.ReadOnlyCollection
1[System.String]]と表示されます。
補足情報(FW/ツールのバージョンなど)
VisualStudio 2019 community
Prism.Unity 6.3.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/21 23:04
2019/07/21 23:32
2019/07/23 23:32