[Livet]非アクティブ時におけるWindowInteractionMessageActionの注意点
2020-03-25
Livetを用いてViewModelからViewを操作する為に
WindowInteractionMessageActionを用いる際、
デフォルトのままだとWindowが非アクティブの状態では
正しくメッセージが送信されない(実行されない)。
例として、
OnContentRendered→最小化(非アクティブ化)→3秒待つ→最大化 を行う場合は、
下記のように InvokeActionOnlyWhenWindowIsActive="False" を指定する。
<!-- View.xaml -->
<Window x:Class="WpfApp11.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp11"
mc:Ignorable="d"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:l="http://schemas.livet-mvvm.net/2011/wpf"
Title="View" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<i:Interaction.Triggers>
<i:EventTrigger EventName ="ContentRendered">
<l:LivetCallMethodAction MethodTarget="{Binding}" MethodName="OnContentRendered" />
</i:EventTrigger>
<l:InteractionMessageTrigger MessageKey="WindowAction" Messenger="{Binding Messenger}">
<l:WindowInteractionMessageAction InvokeActionOnlyWhenWindowIsActive="False" />
</l:InteractionMessageTrigger>
</i:Interaction.Triggers>
<Grid>
</Grid>
</Window>
// ViewMode.cs
using Livet.Messaging.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApp11
{
public class ViewModel : Livet.ViewModel
{
public void OnContentRendered()
{
Messenger.Raise(new WindowActionMessage(WindowAction.Minimize, "WindowAction"));
System.Threading.Thread.Sleep(3000);
Messenger.Raise(new WindowActionMessage(WindowAction.Normal, "WindowAction"));
}
}
}
関連記事
よく使う初期環境
App.xaml <Application x:Class="Sample ...
Material Design In XAML ToolkitのComboBoxを旧型式にする
コンボボックスにMaterial Design In XAML Toolkitを ...
Microsoftのデザインシステム「Fluent Design」
Fluent Designとは Microsoftが2017年に提唱したデザイン ...
よく使う初期環境 MaterialDesignThemes 3.1.3 対応版
よく使う初期環境 のMaterialDesignThemes 3.1.3 対応版 ...
Material Design In XAML ToolkitとMahApps.Metroを用いたマテリアルデザイン風Window
Material Design In XAML Toolkitを用いることで、簡 ...
ディスカッション
コメント一覧
まだ、コメントがありません