ダイアログ表示を行うビューモデル(その5)

ダイアログ表示を行うビューモデル(その4)の続きです。

前回ライブラリを使ったアプリケーション例のビューモデル関係まで書いたので、今回はビュー関係です。

最初に App.xaml と App.xaml.cs へ SessionEnding の設定をしておきます。
App.xaml

<Application x:Class="TestApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml" SessionEnding="Application_SessionEnding">
    <Application.Resources>
         
    </Application.Resources>
</Application>

App.xaml.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

using MakCraft.ViewModels;

namespace TestApp
{
    /// <summary>
    /// App.xaml の相互作用ロジック
    /// </summary>
    public partial class App : Application
    {
        private void Application_SessionEnding(object sender, SessionEndingCancelEventArgs e)
        {
            if (!ViewModelUtility.IsReadyCloseAllWindows)
            {
                var status = MessageBox.Show(
                    "閉じることのできないウィンドウがあります。強制的に閉じてもよろしいですか(保存していないデータなどは破棄されます)?",
                    "クローズできません", MessageBoxButton.YesNo);
                if (status != MessageBoxResult.Yes)
                {
                    // セッションの終了を禁止する
                    e.Cancel = true;
                }
            }0
        }
    }
}

次は MainWindow.xaml です。

<Window x:Class="TestApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:mb="clr-namespace:MakCraft.Behaviors;assembly=TransitionViewModelBase"
        xmlns:vm="clr-namespace:TestApp.ViewModels"
        Title="MainWindow" SizeToContent="WidthAndHeight">
    <Window.DataContext>
        <vm:MainWindowViewModel />
    </Window.DataContext>
    <i:Interaction.Triggers>
        <ei:PropertyChangedTrigger Binding="{Binding ModelessKick}">
            <mb:DialogTransferDataAction
                Parameter="{Binding CommunicationDialog}" DialogType="{Binding DialogType}" DialogMode="Modeless" />
        </ei:PropertyChangedTrigger>

        <ei:PropertyChangedTrigger Binding="{Binding ModalKick}">
            <mb:DialogTransferDataAction
                Parameter="{Binding CommunicationDialog}" DialogType="{Binding DialogType}" DialogMode="Modal"
                ActionCallBack="{Binding DialogActionCallback}" ResultViewModel="{Binding ResultViewModel}" />
        </ei:PropertyChangedTrigger>

        <ei:PropertyChangedTrigger Binding="{Binding DisplayMode}">
            <mb:DisplayModeAction DisplayMode="{Binding DisplayMode}" />
        </ei:PropertyChangedTrigger>
        <ei:PropertyChangedTrigger Binding="{Binding MessageDialogActionParam}">
            <mb:MessageDialogAction
                Parameter="{Binding MessageDialogActionParam}"
                ActionCallBack="{Binding MessageDialogActionCallback}" />
        </ei:PropertyChangedTrigger>
    </i:Interaction.Triggers>

    <StackPanel>
        <TextBlock Text="ダイアログの画面遷移のテスト" FontSize="18" HorizontalAlignment="Center" Margin="8" />
        <TextBlock Text="ViewModelStatus を使用して遷移をコントロールする" FontSize="14" HorizontalAlignment="Center" Margin="40 4" />

        <Grid HorizontalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0" Content="Transition1 のデータ:" />
            <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Trans1Text}" MinWidth="50" IsReadOnly="True" />
            <Label Grid.Row="1" Grid.Column="0" Content="Transition2 のデータ:" />
            <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Trans2Text}" MinWidth="50" IsReadOnly="True" />
            <Label Grid.Row="2" Grid.Column="0" Content="Transition3 のデータ:" />
            <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Trans3Text}" MinWidth="50" IsReadOnly="True" />
        </Grid>

        <Button Content="遷移表示" Command="{Binding ShowTransitionWindowCommand}" Margin="8" />

        <Border BorderBrush="Bisque"  BorderThickness="1" Margin="2" />
        
        <Button Content="選択後に別ウィンドウ" Command="{Binding ShowTransAfterSelectedCommand}" Margin="8" />

        <Button Content="複数表示" Command="{Binding ShowMultipleWindowCommand}" Margin="8" />

        <Border BorderBrush="Bisque"  BorderThickness="1" Margin="2" />

        <Button Content="モーダル ダイアログ表示(DataAnnotationsを利用した検証)" Command="{Binding ShowModalWindowCommand}" Margin="8" />

        <Button Content="モーダル ダイアログ表示" Command="{Binding ShowModalWindow2Command}" Margin="8" />

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
            <TextBlock Text="選択されたアイテム:" VerticalAlignment="Center" />
            <TextBox Text="{Binding SelectedBook}" MinWidth="100" Margin="4" />
        </StackPanel>

        <Border BorderBrush="Bisque"  BorderThickness="1" Margin="2" />

        <Button Content="GC" Command="{Binding GcCoomand}" Margin="8" />

        <Button Content="ウィンドウ クローズの可否を変更" Command="{Binding ChangeClosableCommand}" Margin="8" />

        <Button Content="閉じる" Command="{Binding WindowCloseCommand}" Margin="8" />
    </StackPanel>
</Window>

続けて「AfterSelectWindow」ウィンドウを作成します。

<Window x:Class="TestApp.AfterSelectWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:mb="clr-namespace:MakCraft.Behaviors;assembly=TransitionViewModelBase"
        xmlns:vm="clr-namespace:TestApp.ViewModels"
        Title="AfterSelectWindow" Height="300" Width="300">
    <Window.DataContext>
        <vm:AfterSelectWindowViewModel />
    </Window.DataContext>
    <i:Interaction.Triggers>
        <ei:PropertyChangedTrigger Binding="{Binding DisplayMode}">
            <mb:DisplayModeAction DisplayMode="{Binding DisplayMode}" />
        </ei:PropertyChangedTrigger>

        <i:EventTrigger EventName="Closed">
            <i:InvokeCommandAction Command="{Binding WindowClosedCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <StackPanel>
        <TextBlock Text="選択後のウィンドウ" HorizontalAlignment="Center" FontSize="18" Margin="8" />

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="4">
            <TextBlock Text="選択したもの: " VerticalAlignment="Center" />
            <TextBox IsReadOnly="True" MinWidth="80" Text="{Binding SelectedItem}" />
        </StackPanel>

        <Button Content="GC" Command="{Binding GcCoomand}" Margin="8" />

        <Button Content="閉じる" Margin="4" Command="{Binding CompleteCommand}" />
    </StackPanel>
</Window>

続けて「ModalWindow1」ウィンドウを作成します。

<Window x:Class="TestApp.ModalWindow1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:mb="clr-namespace:MakCraft.Behaviors;assembly=TransitionViewModelBase"
        xmlns:vm="clr-namespace:TestApp.ViewModels"
        Title="ModalWindow1" Name="Window" SizeToContent="WidthAndHeight">
    <Window.DataContext>
        <vm:ModalWindow1ViewModel />
    </Window.DataContext>
    <Window.Resources>
        <Style TargetType="ComboBox">
            <Setter Property="Margin" Value="10 0 0 0" />
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value>
                    <ControlTemplate>
                        <DockPanel>
                            <TextBlock Foreground="Red" FontSize="20">!</TextBlock>
                            <Border BorderBrush="Red" BorderThickness="1">
                                <AdornedElementPlaceholder />
                            </Border>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter
                        Property="ToolTip"
                        Value="{Binding RelativeSource={x:Static RelativeSource.Self},Path=(Validation.Errors)[0].ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <i:Interaction.Triggers>
        <!-- DialogResult セット用のトリガ -->
        <ei:PropertyChangedTrigger Binding="{Binding Result}">
            <ei:ChangePropertyAction
                TargetObject="{Binding ElementName=Window}" PropertyName="DialogResult" Value="{Binding Result}" />
        </ei:PropertyChangedTrigger>

        <!-- MessageBox 表示用のトリガ -->
        <ei:PropertyChangedTrigger Binding="{Binding MessageDialogActionParam}">
            <mb:MessageDialogAction
                Parameter="{Binding MessageDialogActionParam}"
                ActionCallBack="{Binding MessageDialogActionCallback}" />
        </ei:PropertyChangedTrigger>
    </i:Interaction.Triggers>

    <DockPanel>
        <TextBlock DockPanel.Dock="Top" Text="モーダルダイアログ" HorizontalAlignment="Center" FontSize="18" Margin="8" />

        <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right" Margin="6">
            <Button Content="OK" MinWidth="80" Padding="4" Command="{Binding OkCommand}" />
            <Button Content="Cancel" MinWidth="80" Padding="4">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:ChangePropertyAction
                            TargetObject="{Binding ElementName=Window}" PropertyName="DialogResult" Value="False" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
        </StackPanel>

        <TextBox
            DockPanel.Dock="Bottom" MinWidth="100" Margin="6" HorizontalAlignment="Right" IsReadOnly="True"
            Text="{Binding MessageText}" />

        <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right" Margin="6">
            <Button
                Content="メッセージ表示1" MinWidth="100" Padding="4" Margin="6 0 0 0"
                Command="{Binding MessageCommand}" />
            <Button
                Content="メッセージ表示2" MinWidth="100" Padding="4" Margin="6 0 0 0"
                Command="{Binding Message2Command}" />
        </StackPanel>
        
        <Grid Margin="8">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <ComboBox
                Grid.Row="0" Grid.Column="0" MinWidth="100" VerticalAlignment="Top"
                ItemsSource="{Binding Books}" DisplayMemberPath="Title"
                SelectedItem="{Binding SelectedBook, ValidatesOnDataErrors=True}" />
            <TextBox
                Grid.Row="0" Grid.Column="1" IsReadOnly="True" VerticalScrollBarVisibility="Auto"
                MinHeight="50" MinWidth="100" Margin="10 0 0 0" Padding="4" TextWrapping="Wrap"
                Text="{Binding SelectedBook.Note}" />
        </Grid>
    </DockPanel>
</Window>

続けて「ModalWindow2」ウィンドウを作成します。

<Window x:Class="TestApp.ModalWindow2"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:vm="clr-namespace:TestApp.ViewModels"
        Title="ModalWindow2" Name="Window" SizeToContent="WidthAndHeight">
    <Window.DataContext>
        <vm:ModalWindow2ViewModel />
    </Window.DataContext>
    <i:Interaction.Triggers>
        <!-- DialogResult セット用のトリガ -->
        <ei:PropertyChangedTrigger Binding="{Binding Result}">
            <ei:ChangePropertyAction
                TargetObject="{Binding ElementName=Window}" PropertyName="DialogResult" Value="{Binding Result}" />
        </ei:PropertyChangedTrigger>
    </i:Interaction.Triggers>

    <DockPanel>
        <TextBlock DockPanel.Dock="Top" Text="モーダルダイアログ" HorizontalAlignment="Center" FontSize="18" Margin="8" />

        <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right" Margin="6">
            <Button Content="OK" MinWidth="80" Padding="4" Command="{Binding OkCommand}" />
            <Button Content="Cancel" MinWidth="80" Padding="4">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:ChangePropertyAction
                            TargetObject="{Binding ElementName=Window}" PropertyName="DialogResult" Value="False" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
        </StackPanel>

        <Grid Margin="8">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <ComboBox
                Grid.Row="0" Grid.Column="0" MinWidth="100" VerticalAlignment="Top"
                ItemsSource="{Binding Books}" DisplayMemberPath="Title"
                SelectedItem="{Binding SelectedBook, ValidatesOnDataErrors=True}" />
            <TextBox
                Grid.Row="0" Grid.Column="1" IsReadOnly="True" VerticalScrollBarVisibility="Auto"
                MinHeight="50" MinWidth="100" Margin="10 0 0 0" Padding="4" TextWrapping="Wrap"
                Text="{Binding SelectedBook.Note}" />
        </Grid>
    </DockPanel>
</Window>

続けて「MultipleWindow」ウィンドウを作成します。

<Window x:Class="TestApp.MultipleWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:mb="clr-namespace:MakCraft.Behaviors;assembly=TransitionViewModelBase"
        xmlns:vm="clr-namespace:TestApp.ViewModels"
        Title="MultipleWindow" Height="300" Width="300">
    <Window.DataContext>
        <vm:MultipleWindowViewModel />
    </Window.DataContext>
    <i:Interaction.Triggers>
        <ei:PropertyChangedTrigger Binding="{Binding DisplayMode}">
            <mb:DisplayModeAction DisplayMode="{Binding DisplayMode}" />
        </ei:PropertyChangedTrigger>
    </i:Interaction.Triggers>

    <StackPanel>
        <TextBlock Text="複数表示ウィンドウ(遷移しない)" FontSize="18" HorizontalAlignment="Center" Margin="8" />

        <Button Content="ウィンドウ クローズの可否を変更" Command="{Binding ChangeClosableCommand}" Margin="8" />

        <Button Content="閉じる" Command="{Binding WindowCloseCommand}" Margin="8" />
    </StackPanel>
</Window>

続けて「SelectWindow」ウィンドウを作成します。

<Window x:Class="TestApp.SelectWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:mb="clr-namespace:MakCraft.Behaviors;assembly=TransitionViewModelBase"
        xmlns:vm="clr-namespace:TestApp.ViewModels"
        Title="SelectWindow" SizeToContent="WidthAndHeight">
    <Window.DataContext>
        <vm:SelectWindowViewModel />
    </Window.DataContext>
    <i:Interaction.Triggers>
        <ei:PropertyChangedTrigger Binding="{Binding DisplayMode}">
            <mb:DisplayModeAction DisplayMode="{Binding DisplayMode}" />
        </ei:PropertyChangedTrigger>

        <i:EventTrigger EventName="Closed">
            <i:InvokeCommandAction Command="{Binding WindowClosedCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <DockPanel>
        <TextBlock DockPanel.Dock="Top" Text="選択ウィンドウ" HorizontalAlignment="Center" FontSize="18" Margin="8" />

        <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Content="OK" MinWidth="80" Margin="4" Command="{Binding CompleteCommand}" />
            <Button Content="Cancel" MinWidth="80" Margin="4" Command="{Binding WindowCloseCommand}" />
        </StackPanel>

        <ComboBox DockPanel.Dock="Bottom" Margin="4" ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}" />
    </DockPanel>
</Window>

続けて「TransitionWindow1」ウィンドウを作成します。

<Window x:Class="TestApp.TransitionWindow1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:mb="clr-namespace:MakCraft.Behaviors;assembly=TransitionViewModelBase"
        xmlns:vm="clr-namespace:TestApp.ViewModels"
        Title="TransitionWindow1" Height="300" SizeToContent="Width">
    <Window.DataContext>
        <vm:TransitionWindow1ViewModel />
    </Window.DataContext>
    <Window.Resources>
        <Style TargetType="TextBox">
            <!-- エラー項目の ! 表記用の設定 ここから -->
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value>
                    <ControlTemplate>
                        <DockPanel>
                            <TextBlock Foreground="Red" FontSize="20">!</TextBlock>
                            <Border BorderBrush="Red" BorderThickness="1">
                                <AdornedElementPlaceholder />
                            </Border>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter
                        Property="ToolTip"
                        Value="{Binding RelativeSource={x:Static RelativeSource.Self},Path=(Validation.Errors)[0].ErrorContent}" />
                </Trigger>
            </Style.Triggers>
            <!-- エラー項目の ! 表記用の設定 ここまで -->
        </Style>
    </Window.Resources>
    <i:Interaction.Triggers>
        <ei:PropertyChangedTrigger Binding="{Binding ModelessKick}">
            <mb:DialogTransferDataAction
                Parameter="{Binding CommunicationDialog}" DialogType="{Binding DialogType}" DialogMode="Modeless" />
        </ei:PropertyChangedTrigger>

        <ei:PropertyChangedTrigger Binding="{Binding DisplayMode}">
            <mb:DisplayModeAction DisplayMode="{Binding DisplayMode}" />
        </ei:PropertyChangedTrigger>

        <i:EventTrigger EventName="Closed">
            <i:InvokeCommandAction Command="{Binding WindowClosedCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <StackPanel FocusManager.FocusedElement="{Binding ElementName=InputBox}">
        <TextBlock Text="モードレス ダイアログの画面遷移のテスト" FontSize="18" HorizontalAlignment="Center" Margin="8" />

        <Grid HorizontalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0" Content="Transition1 のデータ:" />
            <TextBox
                Grid.Row="0" Grid.Column="1" Name="InputBox" MinWidth="50"
                Text="{Binding Trans1Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" />
        </Grid>

        <Button Content="画面遷移2を表示" Command="{Binding ShowTransitionWindow2Command}" Margin="8" />

        <Button Content="GC" Command="{Binding GcCoomand}" Margin="8" />

        <Button Content="閉じる" Command="{Binding WindowCloseCommand}" Margin="8" />
    </StackPanel>
</Window>

続けて「TransitionWindow2」ウィンドウを作成します。

<Window x:Class="TestApp.TransitionWindow2"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:mb="clr-namespace:MakCraft.Behaviors;assembly=TransitionViewModelBase"
        xmlns:vm="clr-namespace:TestApp.ViewModels"
        Title="TransitionWindow2" Height="300" SizeToContent="Width">
    <Window.DataContext>
        <vm:TransitionWindow2ViewModel />
    </Window.DataContext>
    <i:Interaction.Triggers>
        <ei:PropertyChangedTrigger Binding="{Binding ModelessKick}">
            <mb:DialogTransferDataAction
                Parameter="{Binding CommunicationDialog}" DialogType="{Binding DialogType}" DialogMode="Modeless" />
        </ei:PropertyChangedTrigger>

        <ei:PropertyChangedTrigger Binding="{Binding DisplayMode}">
            <mb:DisplayModeAction DisplayMode="{Binding DisplayMode}" />
        </ei:PropertyChangedTrigger>

        <i:EventTrigger EventName="Closed">
            <i:InvokeCommandAction Command="{Binding WindowClosedCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <StackPanel FocusManager.FocusedElement="{Binding ElementName=InputBox}">
        <TextBlock Text="モードレス ダイアログの画面遷移のテスト2" FontSize="18" HorizontalAlignment="Center" Margin="8" />

        <Grid HorizontalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0" Content="Transition1 のデータ:" />
            <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Trans1Text}" MinWidth="50" IsReadOnly="True" />
            <Label Grid.Row="1" Grid.Column="0" Content="データを入力:" />
            <TextBox Grid.Row="1" Grid.Column="1" Name="InputBox" MinWidth="50"
                     Text="{Binding Trans2Text, UpdateSourceTrigger=PropertyChanged}" />
        </Grid>

        <Button Content="画面遷移3を表示" Command="{Binding ShowTransitionWindow3Command}" Margin="8" />

        <Button Content="GC" Command="{Binding GcCoomand}" Margin="8" />

        <Button Content="閉じる" Command="{Binding WindowCloseCommand}" Margin="8" />
    </StackPanel>
</Window>

最後に「TransitionWindow3」ウィンドウを作成します。

<Window x:Class="TestApp.TransitionWindow3"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:mb="clr-namespace:MakCraft.Behaviors;assembly=TransitionViewModelBase"
        xmlns:vm="clr-namespace:TestApp.ViewModels"
        Title="TransitionWindow3" Height="300" SizeToContent="Width">
    <Window.DataContext>
        <vm:TransitionWindow3ViewModel />
    </Window.DataContext>
    <i:Interaction.Triggers>
        <ei:PropertyChangedTrigger Binding="{Binding DisplayMode}">
            <mb:DisplayModeAction DisplayMode="{Binding DisplayMode}" />
        </ei:PropertyChangedTrigger>

        <i:EventTrigger EventName="Closed">
            <i:InvokeCommandAction Command="{Binding WindowClosedCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <StackPanel FocusManager.FocusedElement="{Binding ElementName=InputBox}">
        <TextBlock Text="モードレス ダイアログの画面遷移のテスト3" FontSize="18" HorizontalAlignment="Center" Margin="8" />

        <Grid HorizontalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto" />
                <ColumnDefinition Width="auto" />
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0" Content="Transition1 のデータ:" />
            <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Trans1Text}" MinWidth="50" IsReadOnly="True" />
            <Label Grid.Row="1" Grid.Column="0" Content="Transition2 のデータ:" />
            <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Trans2Text}" MinWidth="50" IsReadOnly="True" />
            <Label Grid.Row="2" Grid.Column="0" Content="データを入力:" />
            <TextBox Grid.Row="2" Grid.Column="1" Name="InputBox" MinWidth="50"
                     Text="{Binding Trans3Text, UpdateSourceTrigger=PropertyChanged}" />
        </Grid>

        <Button Content="一連の手順の完了" Command="{Binding CompleteCommand}" Margin="8" />

        <Button Content="GC" Command="{Binding GcCoomand}" Margin="8" />

        <Button Content="閉じる" Command="{Binding WindowCloseCommand}" Margin="8" />
    </StackPanel>
</Window>

以上でライブラリを使ったアプリケーション例が完成です。

アプリケーション例を含めた TransitionViewModelBase の ZIP ファイルを ViewModelBase のページからダウンロードできるようにしたので、ファイルがほしい方はそちらから入手してください。


ダイアログ表示を行うビューモデル ベース(インデックス)


ダイアログ表示を行うビューモデル(その5)」への1件のフィードバック

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です