Skip to content

Commit 4c420ff

Browse files
Mrxx99Keboo
andauthored
Adding ShowMeTheXaml to MahAppsDragablzDemo (#1497)
* added ShowMeTheXaml to MahAppsDragablzDemo * Rebased on master and fixed conflicts Fixed ControlHelper attached property in MahApps Fixed Copy button on SMTX popup Co-authored-by: Kevin B <[email protected]>
1 parent 1c136f8 commit 4c420ff

File tree

10 files changed

+207
-42
lines changed

10 files changed

+207
-42
lines changed

MahMaterialDragablzMashUp/App.xaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
55
xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz"
6+
xmlns:smtx="clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML"
7+
xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit"
8+
xmlns:smtxAe="clr-namespace:ShowMeTheXAML.AvalonEdit;assembly=ShowMeTheXAML.AvalonEdit"
9+
xmlns:system="clr-namespace:System;assembly=mscorlib"
10+
xmlns:mahDemo="clr-namespace:MahAppsDragablzDemo"
611
StartupUri="MainWindow.xaml">
712
<Application.Resources>
813
<ResourceDictionary>
@@ -22,6 +27,9 @@
2227
<!-- Dragablz Material Design -->
2328
<ResourceDictionary Source="pack://application:,,,/Dragablz;component/Themes/materialdesign.xaml"/>
2429

30+
<!-- ShowMeTheXaml -->
31+
<ResourceDictionary Source="pack://application:,,,/ShowMeTheXAML.AvalonEdit;component/Themes/xamldisplayer.xaml" />
32+
2533
</ResourceDictionary.MergedDictionaries>
2634
<!-- MahApps Brushes -->
2735
<!--<SolidColorBrush x:Key="HighlightBrush" Color="{DynamicResource Primary700}"/>
@@ -42,6 +50,95 @@
4250

4351
<!-- Dragablz Material Design -->
4452
<Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource MaterialDesignTabablzControlStyle}" />
53+
54+
<Style TargetType="smtx:XamlDisplay" BasedOn="{StaticResource {x:Type smtx:XamlDisplay}}">
55+
<Style.Resources>
56+
<ResourceDictionary>
57+
<ResourceDictionary.MergedDictionaries>
58+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
59+
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
60+
</ResourceDictionary.MergedDictionaries>
61+
62+
<smtxAe:TextDocumentValueConverter x:Key="TextDocumentValueConverter"/>
63+
</ResourceDictionary>
64+
</Style.Resources>
65+
<Setter Property="VerticalContentAlignment" Value="Bottom" />
66+
<Setter Property="HorizontalContentAlignment" Value="Right" />
67+
<Setter Property="mahDemo:XamlDisplayEx.ButtonDock" Value="Right" />
68+
<Setter Property="Formatter">
69+
<Setter.Value>
70+
<smtx:XamlFormatter NewLineOnAttributes="True" Indent=" ">
71+
<smtx:XamlFormatter.NamespacesToRemove>
72+
<system:String>http://materialdesigninxaml.net/winfx/xaml/themes</system:String>
73+
</smtx:XamlFormatter.NamespacesToRemove>
74+
</smtx:XamlFormatter>
75+
</Setter.Value>
76+
</Setter>
77+
<Setter Property="Template">
78+
<Setter.Value>
79+
<ControlTemplate TargetType="smtx:XamlDisplay">
80+
<DockPanel>
81+
<materialDesign:PopupBox DockPanel.Dock="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(mahDemo:XamlDisplayEx.ButtonDock)}"
82+
Padding="10" StaysOpen="True" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
83+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
84+
x:Name="PopupBox">
85+
<materialDesign:PopupBox.ToggleContent>
86+
<materialDesign:PackIcon Kind="Xaml" Cursor="Hand" ToolTip="View XAML"
87+
Foreground="{DynamicResource PrimaryHueDarkBrush}"
88+
Background="Transparent"
89+
Margin="3">
90+
<materialDesign:PackIcon.Style>
91+
<Style TargetType="materialDesign:PackIcon" BasedOn="{StaticResource {x:Type materialDesign:PackIcon}}">
92+
<Setter Property="Opacity" Value="0.2" />
93+
<Style.Triggers>
94+
<Trigger Property="IsMouseOver" Value="True">
95+
<Setter Property="Opacity" Value="1" />
96+
</Trigger>
97+
</Style.Triggers>
98+
</Style>
99+
</materialDesign:PackIcon.Style>
100+
</materialDesign:PackIcon>
101+
</materialDesign:PopupBox.ToggleContent>
102+
<Border MaxHeight="600" MaxWidth="800">
103+
<DockPanel>
104+
<Button
105+
Margin="0 10 0 0"
106+
Tag="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}}"
107+
HorizontalAlignment="Right"
108+
Command="Copy"
109+
CommandParameter="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}}"
110+
Content="_COPY"
111+
DockPanel.Dock="Bottom"
112+
Style="{StaticResource MaterialDesignRaisedButton}">
113+
</Button>
114+
<avalonEdit:TextEditor Document="{Binding Xaml, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource TextDocumentValueConverter}}"
115+
Style="{StaticResource AvalonTextEditorXamlDisplay}" />
116+
</DockPanel>
117+
</Border>
118+
119+
</materialDesign:PopupBox>
120+
<Grid>
121+
<AdornerDecorator>
122+
<Border BorderBrush="{DynamicResource SecondaryAccentBrush}" Opacity=".4" Margin="-5">
123+
<Border.Style>
124+
<Style TargetType="Border">
125+
<Setter Property="BorderThickness" Value="0" />
126+
<Style.Triggers>
127+
<DataTrigger Binding="{Binding ElementName=PopupBox, Path=IsPopupOpen}" Value="True">
128+
<Setter Property="BorderThickness" Value="5" />
129+
</DataTrigger>
130+
</Style.Triggers>
131+
</Style>
132+
</Border.Style>
133+
</Border>
134+
</AdornerDecorator>
135+
<ContentPresenter />
136+
</Grid>
137+
</DockPanel>
138+
</ControlTemplate>
139+
</Setter.Value>
140+
</Setter>
141+
</Style>
45142
</ResourceDictionary>
46143
</Application.Resources>
47144
</Application>

MahMaterialDragablzMashUp/App.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using MaterialDesignThemes.Wpf;
44
using System.Windows;
55
using MaterialDesignColors;
6+
using ShowMeTheXAML;
67

78
namespace MahMaterialDragablzMashUp
89
{
@@ -13,6 +14,7 @@ public partial class App : Application
1314
{
1415
protected override void OnStartup(StartupEventArgs e)
1516
{
17+
XamlDisplay.Init();
1618
base.OnStartup(e);
1719
}
1820
}

MahMaterialDragablzMashUp/Mah.xaml

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,90 @@
77
xmlns:local="clr-namespace:MahAppsDragablzDemo"
88
xmlns:system="clr-namespace:System;assembly=mscorlib"
99
xmlns:mdix="http://materialdesigninxaml.net/winfx/xaml/themes"
10+
xmlns:smtx="clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML"
1011
mc:Ignorable="d"
1112
d:DesignHeight="300" d:DesignWidth="300">
1213
<UserControl.DataContext>
1314
<local:MahViewModel/>
1415
</UserControl.DataContext>
16+
<UserControl.Resources>
17+
<ObjectDataProvider x:Key="EnumValues"
18+
MethodName="GetValues" ObjectType="{x:Type system:Enum}">
19+
<ObjectDataProvider.MethodParameters>
20+
<x:Type TypeName="local:EnumValues"/>
21+
</ObjectDataProvider.MethodParameters>
22+
</ObjectDataProvider>
23+
</UserControl.Resources>
1524
<StackPanel>
1625
<TextBlock TextWrapping="Wrap">All controls using MahApps themes, will use Material Design pallete.</TextBlock>
1726

1827
<controls:MetroAnimatedSingleRowTabControl TabStripPlacement="Left" Background="Transparent">
1928
<TabItem Header="ListBox">
20-
<ListBox Margin="0 8 0 0">
21-
<ListBoxItem IsSelected="True">MahApps</ListBoxItem>
22-
<ListBoxItem>Dragablz</ListBoxItem>
23-
<ListBoxItem>Material</ListBoxItem>
24-
</ListBox>
29+
<smtx:XamlDisplay Key="ListBox_1">
30+
<ListBox Margin="0 8 0 0">
31+
<ListBoxItem IsSelected="True">MahApps</ListBoxItem>
32+
<ListBoxItem>Dragablz</ListBoxItem>
33+
<ListBoxItem>Material</ListBoxItem>
34+
</ListBox>
35+
</smtx:XamlDisplay>
2536
</TabItem>
2637
<TabItem Header="Button/Switch">
2738
<StackPanel>
28-
<controls:ToggleSwitch IsChecked="True" HorizontalAlignment="Left" />
29-
<Button Width="100" Margin="0 8 0 0" Content="Nice" HorizontalAlignment="Left"
39+
<smtx:XamlDisplay Key="ToggleSwitch_1" HorizontalAlignment="Left">
40+
<controls:ToggleSwitch IsChecked="True" HorizontalAlignment="Left" />
41+
</smtx:XamlDisplay>
42+
<smtx:XamlDisplay Key="AccentSquareButton_1" HorizontalAlignment="Left">
43+
<Button Width="100" Margin="0 8 0 0" Content="Nice" HorizontalAlignment="Left"
3044
Style="{StaticResource MahApps.Styles.Button.AccentedSquare}" />
45+
</smtx:XamlDisplay>
3146
</StackPanel>
3247
</TabItem>
3348
<TabItem Header="Sliders">
3449
<StackPanel>
35-
<Slider Margin="6 16 6 0" TickPlacement="BottomRight" TickFrequency="10" />
36-
<controls:RangeSlider Margin="6 16 6 0" LowerValue="25" UpperValue="75" TickPlacement="BottomRight" TickFrequency="10" />
37-
<controls:RangeSlider Margin="0 16 0 0" LowerValue="25" UpperValue="75" Orientation="Vertical" Height="200" />
50+
<smtx:XamlDisplay Key="Slider_1">
51+
<Slider Margin="6 16 6 0" TickPlacement="BottomRight" TickFrequency="10" />
52+
</smtx:XamlDisplay>
53+
<smtx:XamlDisplay Key="Slider_2">
54+
<controls:RangeSlider Margin="6 16 6 0" LowerValue="25" UpperValue="75" TickPlacement="BottomRight" TickFrequency="10" />
55+
</smtx:XamlDisplay>
56+
<smtx:XamlDisplay Key="Slider_3">
57+
<controls:RangeSlider Margin="0 16 0 0" LowerValue="25" UpperValue="75" Orientation="Vertical" Height="200" />
58+
</smtx:XamlDisplay>
3859
</StackPanel>
3960
</TabItem>
4061
<TabItem Header="NumericUpDown">
4162
<StackPanel>
42-
<controls:NumericUpDown Margin="5" Value="{Binding UpDownValue, ValidatesOnExceptions=True}"/>
43-
<controls:NumericUpDown Culture="ar-EG" FlowDirection="RightToLeft" Margin="5" controls:TextBoxHelper.SelectAllOnFocus="True"/>
63+
<smtx:XamlDisplay Key="NumericUpDown_1">
64+
<controls:NumericUpDown Margin="5" Value="{Binding UpDownValue, ValidatesOnExceptions=True}"/>
65+
</smtx:XamlDisplay>
66+
<smtx:XamlDisplay Key="NumericUpDown_2">
67+
<controls:NumericUpDown Culture="ar-EG" FlowDirection="RightToLeft" Margin="5" controls:TextBoxHelper.SelectAllOnFocus="True"/>
68+
</smtx:XamlDisplay>
4469
</StackPanel>
4570
</TabItem>
4671
<TabItem Header="DataGrid">
47-
<DataGrid ItemsSource="{Binding GridData}" AutoGenerateColumns="False">
48-
<DataGrid.Resources>
49-
<ObjectDataProvider x:Key="EnumValues"
50-
MethodName="GetValues" ObjectType="{x:Type system:Enum}">
51-
<ObjectDataProvider.MethodParameters>
52-
<x:Type TypeName="local:EnumValues"/>
53-
</ObjectDataProvider.MethodParameters>
54-
</ObjectDataProvider>
55-
</DataGrid.Resources>
56-
<DataGrid.Columns>
57-
<DataGridCheckBoxColumn Binding="{Binding IsChecked}"
72+
<smtx:XamlDisplay Key="DataGrid_1">
73+
<DataGrid ItemsSource="{Binding GridData}" AutoGenerateColumns="False">
74+
<DataGrid.Columns>
75+
<DataGridCheckBoxColumn Binding="{Binding IsChecked}"
5876
ElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnStyle}"
5977
EditingElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnEditingStyle}">
60-
<DataGridCheckBoxColumn.Header>
61-
<CheckBox IsChecked="False" IsEnabled="False"/>
62-
</DataGridCheckBoxColumn.Header>
63-
</DataGridCheckBoxColumn>
64-
<mdix:DataGridTextColumn Header="Text" Binding="{Binding Text}"
78+
<DataGridCheckBoxColumn.Header>
79+
<CheckBox IsChecked="False" IsEnabled="False"/>
80+
</DataGridCheckBoxColumn.Header>
81+
</DataGridCheckBoxColumn>
82+
<mdix:DataGridTextColumn Header="Text" Binding="{Binding Text}"
6583
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}"/>
66-
<mdix:DataGridComboBoxColumn Header="Combo" SelectedItemBinding="{Binding EnumValue}" ItemsSource="{Binding Source={StaticResource EnumValues}}"/>
67-
<controls:DataGridNumericUpDownColumn Binding="{Binding IntValue}"
84+
<mdix:DataGridComboBoxColumn Header="Combo" SelectedItemBinding="{Binding EnumValue}" ItemsSource="{Binding Source={StaticResource EnumValues}}"/>
85+
<controls:DataGridNumericUpDownColumn Binding="{Binding IntValue}"
6886
Header="Numeric"
6987
Width="300"
7088
TextAlignment="Center"
7189
Minimum="0"
7290
StringFormat="{}{0} km" />
73-
</DataGrid.Columns>
74-
</DataGrid>
91+
</DataGrid.Columns>
92+
</DataGrid>
93+
</smtx:XamlDisplay>
7594
</TabItem>
7695
</controls:MetroAnimatedSingleRowTabControl>
7796

MahMaterialDragablzMashUp/MainWindow.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
GlowBrush="{DynamicResource MahApps.Brushes.Accent}"
1313
FontFamily="{StaticResource MahApps.Fonts.Default}"
1414
Title="Material-MahApps-Dragablz Mash Up" Height="640" Width="800">
15+
<Window.CommandBindings>
16+
<CommandBinding Command="Copy" Executed="OnCopy" />
17+
</Window.CommandBindings>
1518
<controls:MetroWindow.Flyouts>
1619
<controls:FlyoutsControl>
1720
<controls:Flyout x:Name="LeftFlyout" Position="Left" Header="Settings" wpf:FlyoutAssist.HeaderColorMode="Accent">

MahMaterialDragablzMashUp/MainWindow.xaml.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
namespace MahMaterialDragablzMashUp
1+
using System;
2+
using System.Diagnostics;
3+
using System.Windows;
4+
using System.Windows.Input;
5+
6+
namespace MahMaterialDragablzMashUp
27
{
38
/// <summary>
49
/// Interaction logic for MainWindow.xaml
@@ -9,5 +14,20 @@ public MainWindow()
914
{
1015
InitializeComponent();
1116
}
17+
18+
private void OnCopy(object sender, ExecutedRoutedEventArgs e)
19+
{
20+
if (e.Parameter is string stringValue)
21+
{
22+
try
23+
{
24+
Clipboard.SetDataObject(stringValue);
25+
}
26+
catch (Exception ex)
27+
{
28+
Trace.WriteLine(ex.ToString());
29+
}
30+
}
31+
}
1232
}
1333
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
4+
namespace MahAppsDragablzDemo
5+
{
6+
public static class XamlDisplayEx
7+
{
8+
public static readonly DependencyProperty ButtonDockProperty = DependencyProperty.RegisterAttached(
9+
"ButtonDock", typeof(Dock), typeof(XamlDisplayEx), new PropertyMetadata(default(Dock)));
10+
11+
public static void SetButtonDock(DependencyObject element, Dock value)
12+
{
13+
element.SetValue(ButtonDockProperty, value);
14+
}
15+
16+
public static Dock GetButtonDock(DependencyObject element)
17+
{
18+
return (Dock) element.GetValue(ButtonDockProperty);
19+
}
20+
}
21+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
MahApps.Metro
22
Dragablz
33
Microsoft.CSharp
4+
ShowMeTheXAML
5+
ShowMeTheXAML.AvalonEdit
6+
ShowMeTheXAML.MSBuild
47
System.Data.DataSetExtensions

MainDemo.Wpf/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
FontFamily="{materialDesign:MaterialDesignFont}"
1717
Icon="favicon.ico">
1818
<Window.CommandBindings>
19-
<CommandBinding Command="Copy" Executed="OnCopy"></CommandBinding>
19+
<CommandBinding Command="Copy" Executed="OnCopy" />
2020
</Window.CommandBindings>
2121
<Window.Resources>
2222
<ResourceDictionary>

0 commit comments

Comments
 (0)