Skip to content

Commit bb2067d

Browse files
authored
Fix: Temporary fix issue with center command until mahapps 3 (#2660)
* Fix: Temporary fix issue with center command until mahapps 3 * Docs: #2651
1 parent e3246e2 commit bb2067d

3 files changed

Lines changed: 105 additions & 100 deletions

File tree

Source/NETworkManager/MainWindow.xaml

Lines changed: 58 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
mc:Ignorable="d"
1717
Style="{DynamicResource DefaultWindow}"
1818
MinWidth="800" Width="1024" Height="768" MinHeight="600"
19-
SaveWindowPosition="True" TitleAlignment="Center"
19+
SaveWindowPosition="True" TitleAlignment="Left"
2020
ContentRendered="MetroMainWindow_ContentRendered" StateChanged="MetroWindowMain_StateChanged"
2121
Activated="MetroMainWindow_Activated" Closing="MetroWindowMain_Closing"
2222
d:DataContext="{d:DesignInstance networkManager:MainWindow}">
@@ -26,6 +26,7 @@
2626
<converters:ApplicationNameToTranslatedStringConverter x:Key="ApplicationNameToTranslatedStringConverter" />
2727
<converters:ApplicationNameToIconConverter x:Key="ApplicationNameToIconConverter" />
2828
<converters:IntZeroToVisibilityCollapsedConverter x:Key="IntZeroToVisibilityCollapsedConverter" />
29+
<converters:BooleanReverseToVisibilityCollapsedConverter x:Key="BooleanReverseToVisibilityCollapsedConverter"/>
2930
<!-- ReSharper disable once Xaml.RedundantResource - Used in TrayIcon -->
3031
<ContextMenu x:Key="ContextMenuNotifyIcon" MinWidth="200" Opened="ContextMenu_Opened" x:Shared="False">
3132
<MenuItem Header="{x:Static localization:Strings.Show}" Command="{Binding ShowWindowCommand}">
@@ -66,48 +67,7 @@
6667
</MenuItem>
6768
</ContextMenu>
6869
</mah:MetroWindow.Resources>
69-
<mah:MetroWindow.TitleTemplate>
70-
<DataTemplate>
71-
<Grid
72-
Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type mah:MetroWindow}}, Path=ActualWidth}">
73-
<TextBlock Grid.Column="0" Grid.Row="0"
74-
Margin="8,-1,1,0"
75-
VerticalAlignment="Center"
76-
HorizontalAlignment="Left"
77-
FontFamily="{DynamicResource MahApps.Fonts.Family.Window.Title}"
78-
FontSize="{DynamicResource MahApps.Font.Size.Window.Title}"
79-
Text="{TemplateBinding Content}"
80-
TextTrimming="CharacterEllipsis" />
81-
<Button Grid.Column="0" Grid.Row="0"
82-
Command="{Binding OpenRunCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
83-
VerticalAlignment="Center"
84-
HorizontalAlignment="Center"
85-
Cursor="Hand"
86-
Style="{StaticResource CleanButton}">
87-
<Grid Height="30">
88-
<Grid.ColumnDefinitions>
89-
<ColumnDefinition Width="Auto" />
90-
<ColumnDefinition Width="270" />
91-
</Grid.ColumnDefinitions>
92-
<Rectangle Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2"
93-
Fill="{DynamicResource MahApps.Brushes.Gray10}" />
94-
<Rectangle Grid.Column="0" Grid.Row="0"
95-
Margin="5,0"
96-
Width="20" Height="20"
97-
HorizontalAlignment="Right"
98-
Fill="{DynamicResource MahApps.Brushes.Gray8}">
99-
<Rectangle.OpacityMask>
100-
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=ChevronRight}" />
101-
</Rectangle.OpacityMask>
102-
</Rectangle>
103-
<TextBlock Grid.Column="1" Grid.Row="0"
104-
Style="{StaticResource InfoTextBlock}"
105-
Text="{x:Static localization:Strings.Watermark_RunCommandWithHotKey}" />
106-
</Grid>
107-
</Button>
108-
</Grid>
109-
</DataTemplate>
110-
</mah:MetroWindow.TitleTemplate>
70+
11171
<mah:MetroWindow.InputBindings>
11272
<KeyBinding Command="{Binding OpenRunCommand}" Modifiers="Control+Shift" Key="P" />
11373
</mah:MetroWindow.InputBindings>
@@ -117,7 +77,7 @@
11777
<mah:MetroWindow.LeftWindowCommands>
11878
<mah:WindowCommands ShowSeparators="False">
11979
<!-- Fix some design issues with margin -2 and -1 -->
120-
<Grid Background="{DynamicResource MahApps.Brushes.Gray8}"
80+
<Grid Background="{DynamicResource MahApps.Brushes.Gray10}"
12181
Visibility="{Binding Source={x:Static settings:ConfigurationManager.Current}, Path=IsAdmin, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}"
12282
Margin="-2,-1,0,0">
12383
<TextBlock Text="Administrator" Foreground="{DynamicResource MahApps.Brushes.Gray3}"
@@ -127,69 +87,72 @@
12787
</mah:MetroWindow.LeftWindowCommands>
12888
<mah:MetroWindow.RightWindowCommands>
12989
<mah:WindowCommands ShowSeparators="False">
130-
<Rectangle Width="10" />
131-
<Button Command="{Binding RestartApplicationCommand}" Opacity="1"
132-
Visibility="{Binding IsRestartRequired, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}"
133-
Cursor="Hand">
134-
<StackPanel Orientation="Horizontal">
135-
<Rectangle Width="20" Height="20" Fill="{DynamicResource MahApps.Brushes.Accent}">
90+
<!-- ToDo: CenterWindowCommands https://github.com/MahApps/MahApps.Metro/issues/4419 -->
91+
<Button Command="{Binding Path=OpenRunCommand}"
92+
Cursor="Hand"
93+
Visibility="{Binding Path=FlyoutRunCommandIsOpen, Converter={StaticResource ResourceKey=BooleanReverseToVisibilityCollapsedConverter}}"
94+
Style="{StaticResource ResourceKey=CleanButton}"
95+
Margin="0,0,10,0">
96+
<Grid Height="30">
97+
<Grid.ColumnDefinitions>
98+
<ColumnDefinition Width="Auto" />
99+
<ColumnDefinition Width="270" />
100+
</Grid.ColumnDefinitions>
101+
<Rectangle Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2"
102+
Fill="{DynamicResource ResourceKey=MahApps.Brushes.Gray10}" />
103+
<Rectangle Grid.Column="0" Grid.Row="0"
104+
Margin="5,0"
105+
Width="20" Height="20"
106+
HorizontalAlignment="Right"
107+
Fill="{DynamicResource ResourceKey=MahApps.Brushes.Gray8}">
136108
<Rectangle.OpacityMask>
137-
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=Restart}" />
109+
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=ChevronRight}" />
138110
</Rectangle.OpacityMask>
139111
</Rectangle>
140-
<TextBlock Text="{x:Static localization:Strings.RestartRequired}"
141-
Style="{StaticResource LinkTextBlock}" VerticalAlignment="Center" Margin="5,0,0,0" />
142-
</StackPanel>
112+
<TextBlock Grid.Column="1" Grid.Row="0"
113+
Style="{StaticResource ResourceKey=InfoTextBlock}"
114+
Text="{x:Static Member=localization:Strings.Watermark_RunCommandWithHotKey}" />
115+
</Grid>
116+
</Button>
117+
<Button Command="{Binding RestartApplicationCommand}"
118+
Opacity="1"
119+
Visibility="{Binding IsRestartRequired, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}"
120+
ToolTip="{x:Static localization:Strings.RestartRequired}"
121+
Cursor="Hand">
122+
<Rectangle Width="20" Height="20"
123+
Fill="{DynamicResource MahApps.Brushes.Accent}">
124+
<Rectangle.OpacityMask>
125+
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=ReloadAlert}" />
126+
</Rectangle.OpacityMask>
127+
</Rectangle>
143128
</Button>
144129
<Button Command="{Binding OpenWebsiteCommand}"
145130
Opacity="1"
146131
Visibility="{Binding IsUpdateAvailable, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}"
147132
CommandParameter="{Binding UpdateReleaseUrl, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
148133
Cursor="Hand"
134+
ToolTip="{x:Static localization:Strings.UpdateAvailable}"
149135
Focusable="False">
150136
<Rectangle Width="20" Height="20"
151-
Fill="{DynamicResource MahApps.Brushes.Accent}"
152-
ToolTip="{x:Static localization:Strings.UpdateAvailable}">
137+
Fill="{DynamicResource MahApps.Brushes.Accent}">
153138
<Rectangle.OpacityMask>
154139
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=RocketLaunchOutline}" />
155140
</Rectangle.OpacityMask>
156141
</Rectangle>
157142
</Button>
158143
<Button Command="{Binding UnlockProfileCommand}"
159144
Opacity="1"
145+
Visibility="{Binding Source={x:Static settings:ConfigurationManager.Current}, Path=ProfileManagerShowUnlock, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}"
146+
CommandParameter="{Binding UpdateReleaseUrl, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
160147
Cursor="Hand"
148+
ToolTip="{x:Static localization:Strings.UnlockProfile}"
161149
Focusable="False">
162-
<Button.Style>
163-
<Style TargetType="{x:Type Button}"
164-
BasedOn="{StaticResource MahApps.Styles.Button.WindowCommands}">
165-
<Setter Property="Visibility" Value="Collapsed" />
166-
<Style.Triggers>
167-
<DataTrigger
168-
Binding="{Binding Source={x:Static settings:ConfigurationManager.Current}, Path=ProfileManagerShowUnlock}"
169-
Value="True">
170-
<Setter Property="Visibility" Value="Visible" />
171-
</DataTrigger>
172-
</Style.Triggers>
173-
</Style>
174-
</Button.Style>
175-
<StackPanel Orientation="Horizontal">
176-
<Rectangle Width="20" Height="20" Fill="{DynamicResource MahApps.Brushes.Accent}">
177-
<Rectangle.Style>
178-
<Style TargetType="Rectangle">
179-
<Style.Triggers>
180-
<Trigger Property="IsMouseOver" Value="True">
181-
<Setter Property="Fill" Value="{DynamicResource MahApps.Brushes.Gray3}" />
182-
</Trigger>
183-
</Style.Triggers>
184-
</Style>
185-
</Rectangle.Style>
186-
<Rectangle.OpacityMask>
187-
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Modern Kind=InterfacePassword}" />
188-
</Rectangle.OpacityMask>
189-
</Rectangle>
190-
<TextBlock Text="{x:Static localization:Strings.UnlockProfile}"
191-
Style="{StaticResource LinkTextBlock}" Margin="5,0" />
192-
</StackPanel>
150+
<Rectangle Width="20" Height="20"
151+
Fill="{DynamicResource MahApps.Brushes.Accent}">
152+
<Rectangle.OpacityMask>
153+
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Modern Kind=InterfacePassword}" />
154+
</Rectangle.OpacityMask>
155+
</Rectangle>
193156
</Button>
194157
<ComboBox ItemsSource="{Binding ProfileFiles}"
195158
SelectedItem="{Binding SelectedProfileFile, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
@@ -200,8 +163,7 @@
200163
HorizontalAlignment="Left"
201164
Focusable="False"
202165
VerticalAlignment="Center"
203-
Height="30"
204-
Margin="0,0,10,0">
166+
Height="30">
205167
<ComboBox.ItemTemplate>
206168
<DataTemplate>
207169
<Grid>
@@ -283,13 +245,15 @@
283245
</mah:MetroWindow.RightWindowCommands>
284246
<mah:MetroWindow.Flyouts>
285247
<mah:FlyoutsControl>
286-
<mah:Flyout x:Name="FlyoutRunCommand"
287-
IsKeyboardFocusWithinChanged="FlyoutRunCommand_IsKeyboardFocusWithinChanged"
248+
<mah:Flyout IsKeyboardFocusWithinChanged="FlyoutRunCommand_IsKeyboardFocusWithinChanged"
249+
IsOpen="{Binding FlyoutRunCommandIsOpen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
250+
AreAnimationsEnabled="{Binding FlyoutRunCommandAreAnimationsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
251+
Visibility="{Binding FlyoutRunCommandIsOpen, Converter={StaticResource BooleanToVisibilityConverter}}"
288252
Position="Top"
289253
TitleVisibility="Collapsed"
290254
CloseButtonVisibility="Collapsed"
291255
IsModal="False"
292-
Width="500" MaxHeight="400"
256+
Width="600" MaxHeight="400"
293257
Theme="Adapt">
294258
<mah:Flyout.InputBindings>
295259
<KeyBinding Command="{Binding RunCommandCloseCommand}" Key="Escape" />
@@ -316,6 +280,8 @@
316280
</Rectangle.OpacityMask>
317281
</Rectangle>
318282
<TextBox Grid.Column="1" Grid.Row="0"
283+
FontSize="18"
284+
FontFamily="Consolas"
319285
Text="{Binding RunCommandSearch, UpdateSourceTrigger=PropertyChanged}"
320286
mah:TextBoxHelper.Watermark="{x:Static localization:Strings.Watermark_RunCommand}">
321287
<TextBox.Style>
@@ -327,7 +293,6 @@
327293
</TextBox>
328294
</Grid>
329295
<ListView Grid.Column="0" Grid.Row="2"
330-
x:Name="ListViewRunCommand"
331296
ItemsSource="{Binding RunCommands}"
332297
SelectedItem="{Binding SelectedRunCommand, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
333298
SelectionMode="Single"

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,37 @@ public bool SettingsViewIsOpen
313313
OnPropertyChanged();
314314
}
315315
}
316+
317+
private bool _flyoutRunCommandIsOpen;
316318

319+
public bool FlyoutRunCommandIsOpen
320+
{
321+
get => _flyoutRunCommandIsOpen;
322+
set
323+
{
324+
if (value == _flyoutRunCommandIsOpen)
325+
return;
326+
327+
_flyoutRunCommandIsOpen = value;
328+
OnPropertyChanged();
329+
}
330+
}
331+
332+
private bool _flyoutRunCommandAreAnimationsEnabled;
333+
334+
public bool FlyoutRunCommandAreAnimationsEnabled
335+
{
336+
get => _flyoutRunCommandAreAnimationsEnabled;
337+
set
338+
{
339+
if (value == _flyoutRunCommandAreAnimationsEnabled)
340+
return;
341+
342+
_flyoutRunCommandAreAnimationsEnabled = value;
343+
OnPropertyChanged();
344+
}
345+
}
346+
317347
private bool _isRestartRequired;
318348

319349
public bool IsRestartRequired
@@ -1209,7 +1239,8 @@ private void OpenRunAction()
12091239
{
12101240
ConfigurationManager.OnDialogOpen();
12111241

1212-
FlyoutRunCommand.IsOpen = true;
1242+
FlyoutRunCommandAreAnimationsEnabled = true;
1243+
FlyoutRunCommandIsOpen = true;
12131244
}
12141245

12151246
public ICommand RunCommandDoCommand => new RelayCommand(_ => RunCommandDoAction());
@@ -1285,24 +1316,28 @@ private void RunCommandDo()
12851316
}
12861317

12871318
// Close the flyout
1288-
RunCommandFlyoutClose();
1319+
RunCommandFlyoutClose(true);
12891320
}
12901321

12911322
/// <summary>
12921323
/// Close the run command flyout and clear the search.
12931324
/// </summary>
1294-
private void RunCommandFlyoutClose()
1325+
private async Task RunCommandFlyoutClose(bool clearSearch = false)
12951326
{
1296-
if (!FlyoutRunCommand.IsOpen)
1327+
if (!FlyoutRunCommandIsOpen)
12971328
return;
12981329

1299-
FlyoutRunCommand.AreAnimationsEnabled = false;
1300-
FlyoutRunCommand.IsOpen = false;
1330+
FlyoutRunCommandAreAnimationsEnabled = false;
1331+
FlyoutRunCommandIsOpen = false;
13011332

13021333
ConfigurationManager.OnDialogClose();
13031334

13041335
// Clear the search
1305-
RunCommandSearch = string.Empty;
1336+
if (clearSearch)
1337+
{
1338+
await Task.Delay(500); // Wait for the animation to finish
1339+
RunCommandSearch = string.Empty;
1340+
}
13061341
}
13071342

13081343
#endregion

Website/docs/changelog/next-release.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ Release date: **xx.xx.2023**
4747

4848
## Bugfixes
4949

50+
- **General**
51+
52+
- Fix some design issues for the `Run command` button. The button is now in the right-hand title bar instead of in the center until a better solution is found [#2651](https://github.com/BornToBeRoot/NETworkManager/pull/2651)
53+
5054
- **IP Scanner**
55+
5156
- Copy MAC address to clipboard fixed [#2644](https://github.com/BornToBeRoot/NETworkManager/pull/2644)
5257

5358
## Dependencies, Refactoring & Documentation

0 commit comments

Comments
 (0)