Skip to content

Commit 97d929c

Browse files
committed
Use a routed event to handle closing the properties dialog
1 parent 694056b commit 97d929c

File tree

6 files changed

+63
-5
lines changed

6 files changed

+63
-5
lines changed

AdobeScriptMaker.UI.ViewModels/MainWindows/MainScriptBuilderViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,11 @@ private void Loaded()
4343
{
4444
WeakReferenceMessenger.Default.Send(new InitializeStateMessage(1000, 0));
4545
}
46+
47+
[RelayCommand]
48+
private void PropertiesClosed()
49+
{
50+
int x = 2;
51+
}
4652
}
4753
}

AdobeScriptMaker.UI.ViewModels/Timeline/TimelineViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ private void UpdatePosition(object arg)
7070
Position = updatedPosition;
7171
}
7272

73+
[RelayCommand]
74+
private void PropertiesClosed()
75+
{
76+
SelectedItem = null;
77+
}
78+
7379
public TimelineViewModel()
7480
{
7581
WeakReferenceMessenger.Default.Register<ResizeTimelineComponentMessage>(this);

AdobeScriptMaker.UI/Views/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
WindowStyle="None"
1919
WindowStartupLocation="CenterScreen"
2020
d:DataContext="{d:DesignInstance {x:Type designTimeData:DesignTimeScriptBuilderViewModel}, IsDesignTimeCreatable=True}">
21-
21+
2222
<Window.Resources>
2323
<Style TargetType="{x:Type mainViews:WindowSection}">
2424
<Setter Property="HeaderTemplate">

AdobeScriptMaker.UI/Views/PropertiesEditor/PropertiesEditor.xaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
7+
xmlns:prism="http://prismlibrary.com/"
68
xmlns:local="clr-namespace:AdobeScriptMaker.UI.Views.PropertiesEditor"
79
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
810
xmlns:customControls="clr-namespace:WPFCustomControls;assembly=WPFCustomControls"
@@ -31,6 +33,11 @@
3133
DoubleTemplate="{StaticResource doubleTemplate}"/>
3234
</UserControl.Resources>
3335
<customControls:SideSheet IsActive="{Binding SelectedItem, Converter={StaticResource selectedItemToActiveConverter}}">
36+
<i:Interaction.Triggers>
37+
<i:EventTrigger EventName="CloseClick">
38+
<prism:InvokeCommandAction Command="{Binding PropertiesClosedCommand}"/>
39+
</i:EventTrigger>
40+
</i:Interaction.Triggers>
3441
<Grid Margin="10">
3542
<ItemsControl ItemsSource="{Binding SelectedItem.ComponentData.Parameters}"
3643
ItemTemplateSelector="{StaticResource templateSelector}"

WPFCustomControls/SideSheet.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Windows.Navigation;
1515
using System.Windows.Shapes;
1616
using System.Xml.Linq;
17+
using System.Windows.Controls.Primitives;
1718

1819
namespace WPFCustomControls
1920
{
@@ -28,9 +29,36 @@ public bool IsActive
2829
public static readonly DependencyProperty IsActiveProperty =
2930
DependencyProperty.Register("IsActive", typeof(bool), typeof(SideSheet), new PropertyMetadata(false));
3031

32+
public static readonly RoutedEvent CloseClickEvent = EventManager.RegisterRoutedEvent(
33+
name: "CloseClick",
34+
routingStrategy: RoutingStrategy.Bubble,
35+
handlerType: typeof(RoutedEventHandler),
36+
ownerType: typeof(SideSheet));
37+
38+
public event RoutedEventHandler CloseClick
39+
{
40+
add { AddHandler(CloseClickEvent, value); }
41+
remove { RemoveHandler(CloseClickEvent, value); }
42+
}
43+
3144
static SideSheet()
3245
{
3346
DefaultStyleKeyProperty.OverrideMetadata(typeof(SideSheet), new FrameworkPropertyMetadata(typeof(SideSheet)));
3447
}
48+
49+
public override void OnApplyTemplate()
50+
{
51+
base.OnApplyTemplate();
52+
53+
var closeButton = Template.FindName("PART_CloseButton", this) as ButtonBase;
54+
if (closeButton != null)
55+
closeButton.Click += CloseButton_Click;
56+
}
57+
58+
private void CloseButton_Click(object sender, RoutedEventArgs e)
59+
{
60+
var args = new RoutedEventArgs(CloseClickEvent);
61+
RaiseEvent(args);
62+
}
3563
}
3664
}

WPFCustomControls/Themes/Generic.xaml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,21 @@
1414
BorderBrush="{TemplateBinding BorderBrush}"
1515
BorderThickness="{TemplateBinding BorderThickness}"
1616
Visibility="{TemplateBinding IsActive, Converter={StaticResource booleanToVisibilityConverter}}">
17-
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
18-
VerticalScrollBarVisibility="Auto">
19-
<ContentPresenter></ContentPresenter>
20-
</ScrollViewer>
17+
<Grid>
18+
<Grid.RowDefinitions>
19+
<RowDefinition Height="Auto"></RowDefinition>
20+
<RowDefinition Height="*"></RowDefinition>
21+
</Grid.RowDefinitions>
22+
23+
<Button Name="PART_CloseButton"
24+
HorizontalAlignment="Right"
25+
Margin="3">X</Button>
26+
<ScrollViewer Grid.Row="1"
27+
HorizontalScrollBarVisibility="Disabled"
28+
VerticalScrollBarVisibility="Auto">
29+
<ContentPresenter></ContentPresenter>
30+
</ScrollViewer>
31+
</Grid>
2132
</Border>
2233
</ControlTemplate>
2334
</Setter.Value>

0 commit comments

Comments
 (0)