Skip to content

Commit ffc320a

Browse files
author
Corvin Szimion
committed
2 parents 693f32e + d065de9 commit ffc320a

File tree

4 files changed

+115
-30
lines changed

4 files changed

+115
-30
lines changed

build/GenerateThemesWikiMarkdown.ps1

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Function Main {
1717
# Get xaml files and loop through.
1818
Get-ChildItem $themesFullDir -Filter *.xaml |
1919
Foreach-Object {
20-
$xamlString = Get-Content -Path $_.FullName
20+
$xamlLines = Get-Content -Path $_.FullName
2121
$file = Select-ControlNameFromFile($_.Name)
22-
Read-XamlStyles -xamlString $xamlString -file $file
22+
Read-XamlStyles -xamlLines $xamlLines -file $file
2323
}
2424
Set-Defaults
2525
Format-Output
@@ -33,8 +33,12 @@ Function Format-Output {
3333
}
3434
$previousFile = $style.File;
3535

36-
$linkAndStyleName = "[$($style.Style)]($($baseURL)/$($latestHash)/" +
37-
"$($filePathURL)/MaterialDesignTheme.$($style.File).xaml)";
36+
$styleLink = "$($baseURL)/$($latestHash)/$($filePathURL)/MaterialDesignTheme.$($style.File).xaml"
37+
if ($style.LineNumber) {
38+
$styleLink += "#L$($style.LineNumber)"
39+
}
40+
41+
$linkAndStyleName = "[$($style.Style)]($styleLink)";
3842
if ($style.IsDefault) {
3943
Write-OutputFile ("$listMarkdown $($linkAndStyleName) $defaultStyleText" -replace '\s+', ' ')
4044
}
@@ -70,83 +74,95 @@ Function Select-ControlNameFromFile {
7074
}
7175

7276
Function Read-XamlStyles {
73-
Param ($xamlString, $file)
74-
[xml]$xaml = $xamlString
75-
$xaml.ResourceDictionary.Style |
76-
Foreach-Object {
77+
Param ($xamlLines, $file)
78+
[xml]$xaml = $xamlLines
79+
$lineNum = 1
80+
$xaml.ResourceDictionary.Style |
81+
Foreach-Object {
7782
Write-Output $_
83+
# Get line number by Key or TargetType
84+
$styleLineNumber = $null
85+
$searchKey = if ($_.Key) { $_.Key } else { $_.TargetType }
86+
87+
for ($i = 0; $i -lt $xamlLines.Length; $i++) {
88+
if ($xamlLines[$i] -match [regex]::Escape($searchKey)) {
89+
$styleLineNumber = $i + 1
90+
break
91+
}
92+
}
93+
7894
if ($file -eq "Defaults") {
79-
# Special handeling of Defaults
80-
New-Default -style $_ -file $file
95+
New-Default -style $_ -file $file -lineNumber $styleLineNumber
8196
}
8297
elseif ($file -eq "Generic") {
83-
# Special handeling of Generic
84-
New-GenericDefault -style $_ -file $file
98+
New-GenericDefault -style $_ -file $file -lineNumber $styleLineNumber
8599
}
86-
else{
87-
New-Style -style $_ -file $file
100+
else {
101+
New-Style -style $_ -file $file -lineNumber $styleLineNumber
88102
}
103+
$lineNum++
89104
}
90105
}
91106

92107
Function New-GenericDefault {
93-
Param ($style, $file)
108+
Param ($style, $file, $lineNumber)
94109
$targetType = Read-TargetType($style | Select-Object TargetType)
95110
$basedOn = Read-BasedOn($style | Select-Object BasedOn)
96111
$styleNameValue = ($style | Select-Object Key).Key
97112
$defaultStyleName = if ($null -eq $styleNameValue) { $basedOn } else { $styleNameValue }
98113
Write-Debug "[$file] [Type: $targetType] [StyleNameValue: $styleNameValue] [BasedOn: $basedOn] [DefaultStyleName: $defaultStyleName]"
99-
Add-DefaultStyle -file $file -targetType $targetType -styleName $defaultStyleName
114+
Add-DefaultStyle -file $file -targetType $targetType -styleName $defaultStyleName -lineNumber $lineNumber
100115
}
101116

102-
103117
Function New-Default {
104-
Param ($style, $file)
118+
Param ($style, $file, $lineNumber)
105119
$targetType = Read-TargetType($style | Select-Object TargetType)
106120
$basedOn = Read-BasedOn($style | Select-Object BasedOn)
107121
$styleNameValue = ($style | Select-Object Key).Key
108122
$defaultStyleName = if ($null -eq $styleNameValue) { $basedOn } else { $styleNameValue }
109123
Write-Debug "[$file] [Type: $targetType] [StyleNameValue: $styleNameValue] [BasedOn: $basedOn] [DefaultStyleName: $defaultStyleName]"
110-
Add-DefaultStyle -file $file -targetType $targetType -styleName $defaultStyleName
124+
Add-DefaultStyle -file $file -targetType $targetType -styleName $defaultStyleName -lineNumber $lineNumber
111125
}
112126

113127
Function New-Style {
114-
Param ($style, $file)
128+
Param ($style, $file, $lineNumber)
115129
$targetType = Read-TargetType($style | Select-Object TargetType)
116130
$styleName = ($style | Select-Object Key).Key
117-
$splittedFile = $file.split('.') # Suport for "nested" file names like DataGrid.ComboBox
131+
$splittedFile = $file.split('.') # Support for "nested" file names like DataGrid.ComboBox
118132

119133
if ($targetType -eq $splittedFile[-1]) {
120134
Write-Debug "[Match ] [File: $file] [Type: $targetType] [Style: $styleName]"
121-
Add-Style -targetType $targetType -styleName $styleName -fileName $file
135+
Add-Style -targetType $targetType -styleName $styleName -fileName $file -lineNumber $lineNumber
122136
}
123137
else {
124-
Write-Debug "[Skipped] [File: $file] [Type: $targetType] [Style: $styleName] "
138+
Write-Debug "[Skipped] [File: $file] [Type: $targetType] [Style: $styleName]"
125139
}
126140
}
127141

128142
Function Add-Style {
129-
Param ($targetType, $styleName, $fileName)
130-
$temp = Get-Style -targetType $targetType -styleName $styleName -fileName $file
143+
Param ($targetType, $styleName, $fileName, $lineNumber)
144+
$temp = Get-Style -targetType $targetType -styleName $styleName -fileName $file -lineNumber $lineNumber
131145
$discoverdStyles.Add($temp) | Out-Null
132146
}
133147

134148
Function Get-Style {
135-
Param ($targetType, $styleName, $fileName)
136-
$temp = "" | Select-Object "Control", "Style", "IsDefault", "File"
149+
Param ($targetType, $styleName, $fileName, $lineNumber)
150+
$temp = "" | Select-Object "Control", "Style", "IsDefault", "File", "LineNumber"
137151
$temp.Control = $targetType
138152
$temp.Style = $styleName
139153
$temp.IsDefault = !$styleName
140154
$temp.File = $fileName
155+
$temp.LineNumber = $lineNumber
141156
return $temp
142157
}
143158

144159
Function Add-DefaultStyle {
145-
Param ($file, $targetType, $styleName)
146-
$temp = "" | Select-Object "File", "Type", "Style"
160+
Param ($file, $targetType, $styleName, $lineNumber)
161+
$temp = "" | Select-Object "File", "Type", "Style", "LineNumber"
147162
$temp.File = $file
148163
$temp.Type = $targetType
149164
$temp.Style = $styleName
165+
$temp.LineNumber = $lineNumber
150166
$defaults.Add($temp) | Out-Null
151167
}
152168

src/MainDemo.Wpf/Dialogs.xaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,5 +315,58 @@
315315
</materialDesign:DialogHost>
316316
</smtx:XamlDisplay>
317317
<!--#endregion-->
318+
319+
<Rectangle Style="{StaticResource PageSectionSeparator}" />
320+
321+
<!--#region SAMPLE 6-->
322+
<TextBlock Style="{StaticResource PageSectionTitleTextBlock}" Text="Sample 6" />
323+
324+
<TextBlock MaxWidth="700"
325+
Margin="0,0,0,8"
326+
HorizontalAlignment="Left"
327+
Text="You can also make the background blurry."
328+
TextWrapping="Wrap" />
329+
330+
<DockPanel Margin="0,5,16,5">
331+
<Button Margin="8,0,0,0"
332+
Click="Sample6_ResetBlur"
333+
Content="{materialDesign:PackIcon Kind=Reload}"
334+
DockPanel.Dock="Right"
335+
Style="{StaticResource MaterialDesignFlatButton}"
336+
ToolTip="Reset the BlurRadius of the Dialogs Background to it's default value" />
337+
<Slider x:Name="BlurRadiusSlider"
338+
HorizontalAlignment="Stretch"
339+
DockPanel.Dock="Left"
340+
Maximum="64"
341+
Minimum="1"
342+
Style="{StaticResource MaterialDesignDiscreteSlider}" />
343+
344+
</DockPanel>
345+
346+
<smtx:XamlDisplay UniqueKey="dialogs_sample6">
347+
<materialDesign:DialogHost VerticalAlignment="Center"
348+
ApplyBlurBackground="True"
349+
BlurRadius="{Binding ElementName=BlurRadiusSlider, Path=Value}"
350+
CloseOnClickAway="True"
351+
Identifier="sampleDialog6">
352+
<Border MinWidth="256"
353+
MinHeight="256"
354+
BorderBrush="{DynamicResource PrimaryHueMidBrush}"
355+
BorderThickness="1"
356+
ClipToBounds="True">
357+
<StackPanel VerticalAlignment="Center">
358+
<TextBlock HorizontalAlignment="Center"
359+
FontSize="30"
360+
Text="This is some long text that is going to get blurred out by the dialog."
361+
TextWrapping="Wrap" />
362+
<Button HorizontalAlignment="Center"
363+
VerticalAlignment="Center"
364+
Click="Sample6_OpenDialog"
365+
Content="Open" />
366+
</StackPanel>
367+
</Border>
368+
</materialDesign:DialogHost>
369+
</smtx:XamlDisplay>
370+
<!--#endregion-->
318371
</StackPanel>
319372
</UserControl>

src/MainDemo.Wpf/Dialogs.xaml.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public Dialogs()
1010
{
1111
DataContext = new DialogsViewModel();
1212
InitializeComponent();
13+
BlurRadiusSlider.Value = DialogHost.DefaultBlurRadius;
1314
}
1415

1516
private void Sample1_DialogHost_OnDialogClosing(object sender, DialogClosingEventArgs eventArgs)
@@ -71,4 +72,19 @@ private void Sample5_DialogHost_OnDialogClosed(object sender, DialogClosedEventA
7172
if (!string.IsNullOrWhiteSpace(AnimalTextBox.Text))
7273
AnimalListBox.Items.Add(AnimalTextBox.Text.Trim());
7374
}
75+
76+
private async void Sample6_OpenDialog(object sender, RoutedEventArgs e)
77+
{
78+
var sampleMessageDialog = new SampleMessageDialog
79+
{
80+
Message = { Text = "Some dialog content" }
81+
};
82+
83+
await DialogHost.Show(sampleMessageDialog, "sampleDialog6");
84+
}
85+
86+
private void Sample6_ResetBlur(object sender, RoutedEventArgs e)
87+
{
88+
BlurRadiusSlider.Value = DialogHost.DefaultBlurRadius;
89+
}
7490
}

src/MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ public bool ApplyBlurBackground
607607
nameof(ApplyBlurBackground), typeof(bool), typeof(DialogHost), new PropertyMetadata(default(bool)));
608608

609609

610-
private const double DefaultBlurRadius = 16.0;
610+
public const double DefaultBlurRadius = 16.0;
611611
public double BlurRadius
612612
{
613613
get => (double)GetValue(BlurRadiusProperty);

0 commit comments

Comments
 (0)