Index: Core/Common/src/Core.Common.Controls/Core.Common.Controls.csproj =================================================================== diff -u -r08e8d26a0715f0f3db57c1d3e86256aa06934db4 -r2f8eceba36e55965b2d861414826454261bcbec0 --- Core/Common/src/Core.Common.Controls/Core.Common.Controls.csproj (.../Core.Common.Controls.csproj) (revision 08e8d26a0715f0f3db57c1d3e86256aa06934db4) +++ Core/Common/src/Core.Common.Controls/Core.Common.Controls.csproj (.../Core.Common.Controls.csproj) (revision 2f8eceba36e55965b2d861414826454261bcbec0) @@ -1,10 +1,13 @@  + + + Index: Core/Common/src/Core.Common.Controls/OneWayToggleButton.cs =================================================================== diff -u --- Core/Common/src/Core.Common.Controls/OneWayToggleButton.cs (revision 0) +++ Core/Common/src/Core.Common.Controls/OneWayToggleButton.cs (revision 2f8eceba36e55965b2d861414826454261bcbec0) @@ -0,0 +1,42 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Windows; +using System.Windows.Controls.Primitives; + +namespace Core.Common.Controls +{ + /// + /// Custom that can be used for one-way binding. + /// + public class OneWayToggleButton : ToggleButton + { + protected override void OnClick() + { + RaiseEvent(new RoutedEventArgs(ClickEvent, this)); + + if (Command != null && Command.CanExecute(CommandParameter)) + { + Command.Execute(CommandParameter); + } + } + } +} \ No newline at end of file Index: Core/Common/test/Core.Common.Controls.Test/Core.Common.Controls.Test.csproj =================================================================== diff -u -r08e8d26a0715f0f3db57c1d3e86256aa06934db4 -r2f8eceba36e55965b2d861414826454261bcbec0 --- Core/Common/test/Core.Common.Controls.Test/Core.Common.Controls.Test.csproj (.../Core.Common.Controls.Test.csproj) (revision 08e8d26a0715f0f3db57c1d3e86256aa06934db4) +++ Core/Common/test/Core.Common.Controls.Test/Core.Common.Controls.Test.csproj (.../Core.Common.Controls.Test.csproj) (revision 2f8eceba36e55965b2d861414826454261bcbec0) @@ -4,10 +4,13 @@ ..\..\..\..\lib\NUnitForms.dll + + + Index: Core/Common/test/Core.Common.Controls.Test/OneWayToggleButtonTest.cs =================================================================== diff -u --- Core/Common/test/Core.Common.Controls.Test/OneWayToggleButtonTest.cs (revision 0) +++ Core/Common/test/Core.Common.Controls.Test/OneWayToggleButtonTest.cs (revision 2f8eceba36e55965b2d861414826454261bcbec0) @@ -0,0 +1,123 @@ +// Copyright (C) Stichting Deltares 2021. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System.Threading; +using System.Windows.Controls.Primitives; +using System.Windows.Input; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Core.Common.Controls.Test +{ + [TestFixture] + [Apartment(ApartmentState.STA)] + public class OneWayToggleButtonTest + { + [Test] + public void Constructor_ExpectedValues() + { + // Call + var toggleButton = new OneWayToggleButton(); + + // Assert + Assert.IsInstanceOf(toggleButton); + } + + [Test] + public void OnClick_Always_ClickEventRaised() + { + // Setup + var toggleButton = new TestOneWayToggleButton(); + + var clickCount = 0; + object actualSender = null; + toggleButton.Click += (sender, args) => + { + clickCount++; + actualSender = sender; + }; + + // Call + toggleButton.PerformClick(); + + // Assert + Assert.AreEqual(1, clickCount); + Assert.AreSame(toggleButton, actualSender); + } + + [Test] + public void GivenToggleButtonWithCommandAndCanExecuteTrue_WhenButtonClicked_ThenCommandExecuted() + { + // Given + var mocks = new MockRepository(); + var command = mocks.StrictMock(); + command.Expect(c => c.CanExecuteChanged += null).IgnoreArguments(); + command.Expect(c => c.CanExecute(null)) + .Return(true) + .Repeat.Any(); + command.Expect(c => c.Execute(null)); + mocks.ReplayAll(); + + var toggleButton = new TestOneWayToggleButton + { + Command = command + }; + + // When + toggleButton.PerformClick(); + + // Then + mocks.VerifyAll(); + } + + [Test] + public void GivenToggleButtonWithCommandAndCanExecuteFalse_WhenButtonClicked_ThenCommandNotExecuted() + { + // Given + var mocks = new MockRepository(); + var command = mocks.StrictMock(); + command.Expect(c => c.CanExecuteChanged += null).IgnoreArguments(); + command.Expect(c => c.CanExecute(null)) + .Return(false) + .Repeat.Any(); + mocks.ReplayAll(); + + var toggleButton = new TestOneWayToggleButton + { + Command = command + }; + + // When + toggleButton.PerformClick(); + + // Then + mocks.VerifyAll(); + } + + private class TestOneWayToggleButton : OneWayToggleButton + { + public void PerformClick() + { + OnClick(); + } + } + } +} \ No newline at end of file Index: Core/Gui/src/Core.Gui/Forms/Backstage/BackstageControl.xaml =================================================================== diff -u -rc30c93c3f77e0f07d0859c717c639329a63bd468 -r2f8eceba36e55965b2d861414826454261bcbec0 --- Core/Gui/src/Core.Gui/Forms/Backstage/BackstageControl.xaml (.../BackstageControl.xaml) (revision c30c93c3f77e0f07d0859c717c639329a63bd468) +++ Core/Gui/src/Core.Gui/Forms/Backstage/BackstageControl.xaml (.../BackstageControl.xaml) (revision 2f8eceba36e55965b2d861414826454261bcbec0) @@ -29,6 +29,7 @@ xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls" xmlns:properties="clr-namespace:Core.Gui.Properties" xmlns:backstage="clr-namespace:Core.Gui.Forms.Backstage" + xmlns:controls="clr-namespace:Core.Common.Controls;assembly=Core.Common.Controls" mc:Ignorable="d" d:DataContext="{d:DesignInstance IsDesignTimeCreatable=False, Type={x:Type backstage:BackstageViewModel}}"> @@ -148,29 +149,32 @@ FontSize="35" Text="" /> - +