Skip to content

Commit

Permalink
Fixed MDI child closing & updated to MahApps IconPacks 3xx
Browse files Browse the repository at this point in the history
  • Loading branch information
Toroczkai Attila committed Apr 13, 2020
1 parent 93a81c8 commit c667f0a
Show file tree
Hide file tree
Showing 12 changed files with 568 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Example/Controls/ExampleControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public ExampleControl(MdiChild _mdi)
MDI = _mdi;
Width = double.NaN;
Height = double.NaN;
Unloaded += ExampleControl_Unloaded;
MDI.Closing += ExampleControl_Unloaded;
}

private void ExampleControl_Unloaded(object sender, RoutedEventArgs e)
Expand Down
21 changes: 8 additions & 13 deletions Example/Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,7 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="ControlzEx, Version=3.0.2.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ControlzEx.3.0.2.4\lib\net40\ControlzEx.dll</HintPath>
</Reference>
<Reference Include="MahApps.Metro, Version=1.6.5.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.6.5\lib\net40\MahApps.Metro.dll</HintPath>
</Reference>
<Reference Include="MahApps.Metro.IconPacks, Version=2.3.0.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.IconPacks.2.3.0\lib\net40\MahApps.Metro.IconPacks.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\ControlzEx.3.0.2.4\lib\net40\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xaml" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase">
Expand Down Expand Up @@ -173,7 +161,14 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MahApps.Metro">
<Version>1.6.5</Version>
</PackageReference>
<PackageReference Include="MahApps.Metro.IconPacks">
<Version>3.7.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
47 changes: 39 additions & 8 deletions Example/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,52 @@ public class Extensions
public static double Thickness { get; set; } = 0.25;
public static DrawingImage MakeIcon(object value, object parameter = null)
{
GeometryDrawing geoDrawing = new GeometryDrawing();
geoDrawing.Brush = parameter as Brush ?? Brushes.Black;

GeometryDrawing geoDrawing = new GeometryDrawing
{
Brush = parameter as Brush ?? Brushes.Black
};
geoDrawing.Pen = new Pen(geoDrawing.Brush, Thickness);
if (value is PackIconFontAwesome)
geoDrawing.Geometry = Geometry.Parse((value as PackIconControl<PackIconFontAwesomeKind>).Data);
geoDrawing.Geometry = Geometry.Parse((value as PackIconFontAwesome).Data);
else if (value is PackIconMaterial)
geoDrawing.Geometry = Geometry.Parse((value as PackIconControl<PackIconMaterialKind>).Data);
geoDrawing.Geometry = Geometry.Parse((value as PackIconMaterial).Data);
else if (value is PackIconMaterialLight)
geoDrawing.Geometry = Geometry.Parse((value as PackIconControl<PackIconEntypoKind>).Data);
geoDrawing.Geometry = Geometry.Parse((value as PackIconMaterialLight).Data);
else if (value is PackIconModern)
geoDrawing.Geometry = Geometry.Parse((value as PackIconControl<PackIconModernKind>).Data);
geoDrawing.Geometry = Geometry.Parse((value as PackIconModern).Data);
else if (value is PackIconEntypo)
geoDrawing.Geometry = Geometry.Parse((value as PackIconControl<PackIconEntypoKind>).Data);
geoDrawing.Geometry = Geometry.Parse((value as PackIconEntypo).Data);
else if (value is PackIconOcticons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconControl<PackIconOcticonsKind>).Data);
geoDrawing.Geometry = Geometry.Parse((value as PackIconOcticons).Data);
else if (value is PackIconBoxIcons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconBoxIcons).Data);
else if (value is PackIconEvaIcons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconEvaIcons).Data);
else if (value is PackIconFeatherIcons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconFeatherIcons).Data);
else if (value is PackIconIonicons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconIonicons).Data);
else if (value is PackIconJamIcons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconJamIcons).Data);
else if (value is PackIconMaterialDesign)
geoDrawing.Geometry = Geometry.Parse((value as PackIconMaterialDesign).Data);
else if (value is PackIconMicrons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconMicrons).Data);
else if (value is PackIconPicolIcons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconPicolIcons).Data);
else if (value is PackIconRPGAwesome)
geoDrawing.Geometry = Geometry.Parse((value as PackIconRPGAwesome).Data);
else if (value is PackIconSimpleIcons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconSimpleIcons).Data);
else if (value is PackIconTypicons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconTypicons).Data);
else if (value is PackIconUnicons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconUnicons).Data);
else if (value is PackIconWeatherIcons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconWeatherIcons).Data);
else if (value is PackIconZondicons)
geoDrawing.Geometry = Geometry.Parse((value as PackIconZondicons).Data);
return new DrawingImage { Drawing = new DrawingGroup { Children = { geoDrawing }, Transform = new ScaleTransform(-1, 1) } };
}

Expand Down
29 changes: 20 additions & 9 deletions Example/Main.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Controls:WindowCommands>
<Button Click="ChangeAppStyleButtonClick">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconModern Width="24" Height="24" Kind="Cupcake" />
<iconPacks:PackIconModern Width="24" Height="24" Kind="Cabinet" />
<TextBlock Margin="4 0 0 0" VerticalAlignment="Center" Text="Change App Style..." />
</StackPanel>
</Button>
Expand All @@ -25,14 +25,25 @@
<MenuItem Header="Fixed Window" Click="AddFixedWindow_Click" />
<MenuItem Header="Scroll Window" Click="AddScrollWindow_Click" />
</MenuItem>
<MenuItem Header="Theme">
<MenuItem Header="Generic" Name="Generic" ToolTip="Generic Visual Studio designer theme" Click="Generic_Click" />
<MenuItem Header="Luna" Name="Luna" ToolTip="Blue Windows XP theme" Click="Luna_Click" />
<MenuItem Header="Aero" Name="Aero" ToolTip="Windows Vista/7 theme" Click="Aero_Click" />
<MenuItem Header="Metro" Name="Metro" ToolTip="Windows Vista/7 theme" Click="Metro_Click" />
</MenuItem>
<MenuItem Header="Windows" x:Name="WindowsMenu" x:FieldModifier="private" />
</Menu>
<MenuItem Header="Theme">
<MenuItem Header="Generic" Name="Generic" ToolTip="Generic Visual Studio designer theme" Click="Generic_Click" />
<MenuItem Header="Luna" Name="Luna" ToolTip="Blue Windows XP theme" Click="Luna_Click" />
<MenuItem Header="Aero" Name="Aero" ToolTip="Windows Vista/7 theme" Click="Aero_Click" />
<MenuItem Header="Metro" Name="Metro" ToolTip="Windows Vista/7 theme" Click="Metro_Click" />
</MenuItem>
<MenuItem Header="Windows" Icon="{iconPacks:FontAwesome Kind=WindowsBrands}" Visibility="Visible" IsEnabled="True" FontSize="15">
<StackPanel Width="auto" Margin="-30,-5,-30,-5">
<StackPanel x:Name="WindowsChildMenu" Width="auto" Margin="0"/>
<Separator IsEnabled="False" IsHitTestVisible="False" Margin="0"/>
<MenuItem Click="M_Click" Header="Cascade" Icon="{iconPacks:Entypo Kind=FlowCascade}" Tag="Cascade"/>
<MenuItem Click="M_Click" Header="Horizontally" Icon="{iconPacks:Material Kind=ReorderHorizontal}" Tag="Horizontal"/>
<MenuItem Click="M_Click" Header="Vertically" Icon="{iconPacks:Material Kind=ReorderVertical}" Tag="Vertical"/>
<Separator IsEnabled="False" IsHitTestVisible="False" Margin="0"/>
<MenuItem Header="Close all" Click="M_Click" Icon="{iconPacks:Material Kind=CloseOutline}" Margin="0,0,0,0" Tag="Close_all"/>
</StackPanel>
</MenuItem>

</Menu>
</mdi:MdiContainer.Menu>
<mdi:MdiChild Title="Empty Window Using XAML" Activated="Window_Activated" Deactivated="Window_Deactivated"/>
<mdi:MdiChild Name="Window1" Title="Window Using XAML" Position="20,15" Icon="OriginalLogo.png" Activated="Window_Activated" Deactivated="Window_Deactivated">
Expand Down
101 changes: 76 additions & 25 deletions Example/Main.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using MahApps.Metro.Controls;
using MahApps.Metro.IconPacks;
using System.Windows.Media;
using System.Windows.Data;
using System.Collections.Specialized;

namespace Example
{
Expand All @@ -22,7 +24,7 @@ public Main()
{
InitializeComponent();
_original_title = Title;
Container.Children.CollectionChanged += (o, e) => Menu_RefreshWindows();
Container.Children.CollectionChanged += (o, e) => Menu_RefreshWindows(o, e);
Container.MdiChildTitleChanged += Container_MdiChildTitleChanged;

Container.Children.Add(new MdiChild
Expand Down Expand Up @@ -51,10 +53,9 @@ public Main()

void Container_MdiChildTitleChanged(object sender, RoutedEventArgs e)
{
if (Container.ActiveMdiChild != null && Container.ActiveMdiChild.WindowState == WindowState.Maximized)
Title = _original_title + " - [" + Container.ActiveMdiChild.Title + "]";
else
Title = _original_title;
Title = Container.ActiveMdiChild != null && Container.ActiveMdiChild.WindowState == WindowState.Maximized
? _original_title + " - [" + Container.ActiveMdiChild.Title + "]"
: _original_title;
}

#endregion
Expand All @@ -65,7 +66,7 @@ void Container_MdiChildTitleChanged(object sender, RoutedEventArgs e)
/// Handles the Click event of the Generic control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
private void Generic_Click(object sender, RoutedEventArgs e)
{
Generic.IsChecked = true;
Expand Down Expand Up @@ -164,30 +165,80 @@ private void AddScrollWindow_Click(object sender, RoutedEventArgs e)
/// <summary>
/// Refresh windows list
/// </summary>
void Menu_RefreshWindows()
public void Menu_RefreshWindows(object sender, NotifyCollectionChangedEventArgs Args)
{
switch (Args.Action)
{
case NotifyCollectionChangedAction.Reset:
WindowsChildMenu.Children.Clear();
break;
case NotifyCollectionChangedAction.Add:
for (int i = 0; i < Args.NewItems.Count; i++)
{
MdiChild mdi_ = Args.NewItems[i] as MdiChild;
DrawingImage drawing = ((DrawingImage)mdi_.Icon).Clone();
((GeometryDrawing)((DrawingGroup)drawing.Drawing).Children[0]).Brush = Brushes.Black;
MenuItem mi = new MenuItem { Icon = new Image { Source = drawing, Height = 16, Width = 16 }, Tag = mdi_ };

Binding b = new Binding
{
Source = mdi_,
Path = new PropertyPath(MdiChild.TitleProperty),
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
BindingOperations.SetBinding(mi, HeaderedItemsControl.HeaderProperty, b);
//mi.SetResourceReference(MenuItem.HeaderProperty, mdi_.Title);
mi.Click += (o, e) => mdi_.Focus();

WindowsChildMenu.Children.Insert(0, mi);
}
break;
case NotifyCollectionChangedAction.Remove:
for (int l = 0; l < Args.OldItems.Count; l++)
{
int index = -1;
for (int i = 0; i < WindowsChildMenu.Children.Count; i++)
{
if (((MenuItem)WindowsChildMenu.Children[i]).Tag == Args.OldItems[l])
{
index = i;
break;
}
}
if (index != -1)
{
WindowsChildMenu.Children.RemoveAt(index);
}
}
break;
case NotifyCollectionChangedAction.Replace: // Hmmm
break;
case NotifyCollectionChangedAction.Move: // Hmmm
break;
default:
break;
}
}
private void M_Click(object sender, RoutedEventArgs e)
{
WindowsMenu.Items.Clear();
MenuItem mi;
for (int i = 0; i < Container.Children.Count; i++)
switch (((MenuItem)sender).Tag)
{
MdiChild child = Container.Children[i];
mi = new MenuItem { Header = child.Title };
mi.Click += (o, e) => child.Focus();
WindowsMenu.Items.Add(mi);
case "Cascade":
Container.MdiLayout = MdiLayout.Cascade;
break;
case "Horizontal":
Container.MdiLayout = MdiLayout.TileHorizontal;
break;
case "Vertical":
Container.MdiLayout = MdiLayout.TileVertical;
break;
case "Close all":
Container.Children.Clear();
break;
}
WindowsMenu.Items.Add(new Separator());
WindowsMenu.Items.Add(mi = new MenuItem { Header = "Cascade" });
mi.Click += (o, e) => Container.MdiLayout = MdiLayout.Cascade;
WindowsMenu.Items.Add(mi = new MenuItem { Header = "Horizontally" });
mi.Click += (o, e) => Container.MdiLayout = MdiLayout.TileHorizontal;
WindowsMenu.Items.Add(mi = new MenuItem { Header = "Vertically" });
mi.Click += (o, e) => Container.MdiLayout = MdiLayout.TileVertical;

WindowsMenu.Items.Add(new Separator());
WindowsMenu.Items.Add(mi = new MenuItem { Header = "Close all" });
mi.Click += (o, e) => Container.Children.Clear();
}


#endregion

#region Content Button Events
Expand Down
Loading

0 comments on commit c667f0a

Please sign in to comment.