[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"));
}
}
}
関連記事
[VisualStudio2019]BlendSDKからMicrosoft.Xaml.Behaviors.Wpfへ移行
VisualStudio2019から、BlendSDKが提供されなくなった為、M ...
よく使う初期環境
App.xaml <Application x:Class="Sample ...
Material Design In XAML ToolkitとMahApps.Metroを用いたマテリアルデザイン風Window
Material Design In XAML Toolkitを用いることで、簡 ...
Material Design In XAML ToolkitとMahApps.Metroのテーマ設定
(Material Design In XAML ToolkitとMahApps ...
TextBoxのBindPropertyを即時反映させる
UpdateSourceTrigger=PropertyChanged を付ける ...
ディスカッション
コメント一覧
まだ、コメントがありません