Skip to content

Commit

Permalink
Add IEditableObject interface and behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Sandermann committed Dec 22, 2021
1 parent 34cd1b5 commit 502f6d0
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 80 deletions.
40 changes: 40 additions & 0 deletions src/Moryx.Controls.Demo/ViewModels/EntryEditorViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2020, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
Expand All @@ -13,12 +14,30 @@ namespace Moryx.Controls.Demo.ViewModels
{
public class EntryEditorViewModel : Screen
{
private bool _isEditMode;

public override string DisplayName => "EntryEditor";

public EntryViewModel EntryViewModels { get; }

public ICommand ShowExceptionCommand { get; }

public ICommand BeginEditCmd { get; }

public ICommand EndEditCmd { get; }

public ICommand CancelEditCmd { get; }

public bool IsEditMode
{
get { return _isEditMode; }
private set
{
_isEditMode = value;
NotifyOfPropertyChange(nameof(IsEditMode));
}
}

public EntryEditorViewModel()
{
var entryModel = new EntryClass
Expand Down Expand Up @@ -62,6 +81,27 @@ public EntryEditorViewModel()
EntryViewModels = new EntryViewModel(entry);

ShowExceptionCommand = new RelayCommand(ShowException);
BeginEditCmd = new RelayCommand(o => BeginEdit());
EndEditCmd = new RelayCommand(o => EndEdit());
CancelEditCmd = new RelayCommand(o => CancelEdit());
}

private void EndEdit()
{
IsEditMode = false;
EntryViewModels.EndEdit();
}

private void CancelEdit()
{
IsEditMode = false;
EntryViewModels.CancelEdit();
}

private void BeginEdit()
{
IsEditMode = true;
EntryViewModels.BeginEdit();
}

public void ShowException(object parameter)
Expand Down
53 changes: 52 additions & 1 deletion src/Moryx.Controls.Demo/Views/EntryEditorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,56 @@
xmlns:controls="clr-namespace:Moryx.Controls;assembly=Moryx.Controls"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance viewModels:EntryEditorViewModel}">
<controls:EntryEditor Margin="20" RootEntry="{Binding EntryViewModels}" IsEditMode="True" ShowExceptionCommand="{Binding ShowExceptionCommand}" />
<UserControl.Resources>
<Style x:Key="AnimatedButton" TargetType="EddieButton" BasedOn="{StaticResource {x:Type EddieButton}}">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation AccelerationRatio="1" Duration="0:0:0.2" Storyboard.TargetProperty="Width" From="0"/>
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" BeginTime="00:00:00">
<SplineThicknessKeyFrame KeyTime="0:0:0" Value="0,0,0,0" />
<SplineThicknessKeyFrame KeyTime="0:0:0.2" Value="5,0,0,0" />
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation AccelerationRatio="1" Duration="0:0:0.2" Storyboard.TargetProperty="Width" To="0"/>
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" BeginTime="00:00:00">
<SplineThicknessKeyFrame KeyTime="0:0:0" Value="5,0,0,0" />
<SplineThicknessKeyFrame KeyTime="0:0:0.2" Value="0,0,0,0" />
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>

<ScrollViewer DockPanel.Dock="Top" Margin="0,5,0,5" MinHeight="300" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<StackPanel Orientation="Vertical">
<controls:EntryEditor Margin="20" RootEntry="{Binding EntryViewModels}" IsEditMode="{Binding IsEditMode}" ShowExceptionCommand="{Binding ShowExceptionCommand}" />
<StackPanel Orientation="Horizontal" Margin="0,5,0,5" HorizontalAlignment="Right">
<EddieButton Icon="{CommonShape Pencil}"
Command="{Binding BeginEditCmd}"
Content="Begin Edit"
Style="{StaticResource AnimatedButton}"/>
<EddieButton Icon="{CommonShape Cross}"
Margin="5,0,0,0"
Command="{Binding CancelEditCmd}"
Content="Cancel Edit"
Style="{StaticResource AnimatedButton}"/>
<EddieButton Icon="{CommonShape CheckMark}"
Margin="5,0,0,0"
Command="{Binding EndEditCmd}"
Content="End Edit"
Style="{StaticResource AnimatedButton}"/>
</StackPanel>
</StackPanel>
</ScrollViewer>
</UserControl>
Loading

0 comments on commit 502f6d0

Please sign in to comment.