Skip to content

Commit

Permalink
Merge pull request #50 from soi013/dev
Browse files Browse the repository at this point in the history
Fix CursorTypeAndBooleanConverter by hand not T4
  • Loading branch information
runceel authored May 13, 2020
2 parents 54a7ef8 + d86cacf commit fcb008b
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public object Convert(object value, Type targetType, object parameter, System.Gl
{
if (_isConvertWhenTrueSet)
{
return ConvertWhenTrue;
return ConvertWhenTrue.ToString();
}
}
else
{
if (_isConvertWhenFalseSet)
{
return ConvertWhenFalse;
return ConvertWhenFalse.ToString();
}
}

Expand Down Expand Up @@ -103,11 +103,11 @@ public CursorType ConvertWhenFalse
//View→VM
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (!(value is CursorType)) throw new ArgumentException();
if (!(value is Cursor)) throw new ArgumentException();

var enumValue = (CursorType)value;
var cursorValue = (Cursor)value;

switch(enumValue.ToString())
switch (cursorValue.ToString())
{
case "None":
if (_isConvertBackWhenNoneSet)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Window
x:Class="ViewLayerSupport.Views.CursorTypeToBooleanConverterWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:l="http://schemas.livet-mvvm.net/2011/wpf"
xmlns:v="clr-namespace:ViewLayerSupport.Views"
xmlns:vm="clr-namespace:ViewLayerSupport.ViewModels"
x:Name="Root"
Title="CursorTypeToBooleanConverterWindow"
Width="525"
Height="350">

<Window.Cursor>
<Binding
ElementName="CheckBox"
Mode="TwoWay"
Path="IsChecked">
<Binding.Converter>
<l:CursorTypeAndBooleanConverter
ConvertBackDefaultBooleanValue="False"
ConvertBackWhenCross="False"
ConvertBackWhenWait="True"
ConvertWhenFalse="Cross"
ConvertWhenTrue="Wait" />
</Binding.Converter>
</Binding>
</Window.Cursor>

<StackPanel>
<CheckBox x:Name="CheckBox" Content="Is Wait" />

<Button Click="ChangeWait_Click" Content="Change to Wait" />
<Button Click="ChangeCross_Click" Content="Change to Cross" />
</StackPanel>
</Window>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ViewLayerSupport.Views
{
/// <summary>
/// CursorTypeToBooleanConverterWindow.xaml の相互作用ロジック
/// </summary>
public partial class CursorTypeToBooleanConverterWindow : Window
{
public CursorTypeToBooleanConverterWindow()
{
InitializeComponent();
}

private void ChangeWait_Click(object sender, RoutedEventArgs e)
{
this.Cursor = Cursors.Wait;
}
private void ChangeCross_Click(object sender, RoutedEventArgs e)
{
this.Cursor = Cursors.Cross;
}
}
}
35 changes: 23 additions & 12 deletions Samples/ViewLayerSupport/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,27 @@
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button Margin="5" Content="EnumToBooleanConverter">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<l:TransitionInteractionMessageAction>
<l:DirectInteractionMessage>
<l:TransitionMessage WindowType="{x:Type v:EnumToBooleanConverterWindow}" />
</l:DirectInteractionMessage>
</l:TransitionInteractionMessageAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>
<Button Margin="5" Content="EnumToBooleanConverter">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<l:TransitionInteractionMessageAction>
<l:DirectInteractionMessage>
<l:TransitionMessage WindowType="{x:Type v:EnumToBooleanConverterWindow}" />
</l:DirectInteractionMessage>
</l:TransitionInteractionMessageAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button Margin="5" Content="CursorToBooleanConverter">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<l:TransitionInteractionMessageAction>
<l:DirectInteractionMessage>
<l:TransitionMessage WindowType="{x:Type v:CursorTypeToBooleanConverterWindow}" />
</l:DirectInteractionMessage>
</l:TransitionInteractionMessageAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</StackPanel>
</Window>

0 comments on commit fcb008b

Please sign in to comment.