Skip to content

Commit

Permalink
Merge pull request #127 from michaldivis/master
Browse files Browse the repository at this point in the history
Support for custom icons in PersistentSearch, new documentation
  • Loading branch information
spiegelp authored Feb 21, 2021
2 parents fb13b3b + 3c4830f commit 4298064
Show file tree
Hide file tree
Showing 11 changed files with 381 additions and 14 deletions.
44 changes: 44 additions & 0 deletions MaterialDesignExtensions/Controls/SearchBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,50 @@ public object SearchIcon
}
}

/// <summary>
/// The icon on the left side of the search text box that appears when the text is not empty and replaced the search icon.
/// </summary>
public static readonly DependencyProperty CancelIconProperty = DependencyProperty.Register(
nameof(CancelIcon), typeof(object), typeof(SearchBase), new PropertyMetadata(PackIconKind.ArrowLeft, null));

/// <summary>
/// The icon on the left side of the search text box that appears when the text is not empty and replaced the search icon.
/// </summary>
public object CancelIcon
{
get
{
return GetValue(CancelIconProperty);
}

set
{
SetValue(CancelIconProperty, value);
}
}

/// <summary>
/// The icon on the right side of the search text box that appears when the text is not empty.
/// </summary>
public static readonly DependencyProperty ClearIconProperty = DependencyProperty.Register(
nameof(ClearIcon), typeof(object), typeof(SearchBase), new PropertyMetadata(PackIconKind.Close, null));

/// <summary>
/// The icon on the right side of the search text box that appears when the text is not empty.
/// </summary>
public object ClearIcon
{
get
{
return GetValue(ClearIconProperty);
}

set
{
SetValue(ClearIconProperty, value);
}
}

/// <summary>
/// A source for providing suggestions to search for.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions MaterialDesignExtensions/Themes/SearchTemplates.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<Binding Path="SearchTerm" RelativeSource="{RelativeSource TemplatedParent}" Converter="{StaticResource notNullBooleanConverter}" />
</MultiBinding>
</Button.Visibility>
<md:PackIcon Kind="ArrowLeft" Width="{TemplateBinding IconSize}" Height="{TemplateBinding IconSize}" />
<md:PackIcon Kind="{TemplateBinding CancelIcon}" Width="{TemplateBinding IconSize}" Height="{TemplateBinding IconSize}" />
</Button>
<TextBox x:Name="searchTextBox" Grid.Column="1" md:HintAssist.Hint="{TemplateBinding SearchHint}"
Text="{Binding Path=SearchTerm, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource TemplatedParent}}"
Expand All @@ -96,7 +96,7 @@
<Binding Path="SearchTerm" RelativeSource="{RelativeSource TemplatedParent}" Converter="{StaticResource notNullBooleanConverter}" />
</MultiBinding>
</Button.Visibility>
<md:PackIcon Kind="Close" Width="{TemplateBinding IconSize}" Height="{TemplateBinding IconSize}" />
<md:PackIcon Kind="{TemplateBinding ClearIcon}" Width="{TemplateBinding IconSize}" Height="{TemplateBinding IconSize}" />
</Button>
<controls:AutocompletePopup x:Name="searchSuggestionsPopup"
PlacementTarget="{Binding ElementName=rootBorder}"
Expand Down
13 changes: 11 additions & 2 deletions MaterialDesignExtensionsDemo/Controls/SearchControl.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<UserControl x:Class="MaterialDesignExtensionsDemo.Controls.SearchControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MaterialDesignExtensionsDemo.Controls"
Expand All @@ -18,12 +19,20 @@
<TextBlock x:Name="searchResultTextBlock1" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,128,0,0" />
</Grid>
</Border>
<Border BorderThickness="1" BorderBrush="Black" Height="200" Background="{DynamicResource MaterialDesignPaper}" SnapsToDevicePixels="True" Margin="0,24,0,0">
<TextBlock Text="Dense style" Margin="0,16,0,0"/>
<Border BorderThickness="1" BorderBrush="Black" Height="200" Background="{DynamicResource MaterialDesignPaper}" SnapsToDevicePixels="True" Margin="0,8,0,0">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<mde:PersistentSearch Style="{StaticResource MaterialDesignPersistentSearchDense}" VerticalAlignment="Top" Margin="8" SearchSuggestionsSource="{Binding Path=SearchSuggestionsSource}" Search="SearchHandler1" />
<mde:PersistentSearch Style="{StaticResource MaterialDesignPersistentSearchDense}" VerticalAlignment="Top" Margin="8" SearchSuggestionsSource="{Binding Path=SearchSuggestionsSource}" Search="SearchHandler2" />
<TextBlock x:Name="searchResultTextBlock2" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,128,0,0" />
</Grid>
</Border>
<TextBlock Text="Custom icons" Margin="0,16,0,0"/>
<Border BorderThickness="1" BorderBrush="Black" Height="200" Background="{DynamicResource MaterialDesignPaper}" SnapsToDevicePixels="True" Margin="0,8,0,0">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<mde:PersistentSearch Style="{StaticResource MaterialDesignPersistentSearchDense}" VerticalAlignment="Top" Margin="8" SearchSuggestionsSource="{Binding Path=SearchSuggestionsSource}" Search="SearchHandler3" SearchIcon="{x:Static md:PackIconKind.PrinterSearch}" CancelIcon="{x:Static md:PackIconKind.BellCancel}" ClearIcon="{x:Static md:PackIconKind.CircleArrows}" />
<TextBlock x:Name="searchResultTextBlock3" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,128,0,0" />
</Grid>
</Border>
</StackPanel>
</ScrollViewer>
</Grid>
Expand Down
10 changes: 10 additions & 0 deletions MaterialDesignExtensionsDemo/Controls/SearchControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,15 @@ private void SearchHandler1(object sender, SearchEventArgs args)
{
searchResultTextBlock1.Text = "Your are looking for '" + args.SearchTerm + "'.";
}

private void SearchHandler2(object sender, SearchEventArgs args)
{
searchResultTextBlock2.Text = "Your are looking for '" + args.SearchTerm + "'.";
}

private void SearchHandler3(object sender, SearchEventArgs args)
{
searchResultTextBlock3.Text = "Your are looking for '" + args.SearchTerm + "'.";
}
}
}
4 changes: 2 additions & 2 deletions docs/js/AppViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function AppViewModel(contentDivId, drawer) {
self.documentationItems = [
new DocumentationItem('appbar', 'App bar', 'https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/MaterialWindow.png', 'snippets/documentation/appbar.html'),
new DocumentationItem('autocomplete', 'Autocomplete', 'https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/Autocomplete.png', 'snippets/documentation/autocomplete.html'),
new DocumentationItem('busyoverlay', 'Busy overlay', null, 'snippets/documentation/busyoverlay.html'),
new DocumentationItem('busyoverlay', 'Busy overlay', 'https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/BusyOverlay.png', 'snippets/documentation/busyoverlay.html'),
new DocumentationItem('filesystemcontrols', 'File system controls', 'https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/OpenFileControl1.png', 'snippets/documentation/filesystemcontrols.html'),
new DocumentationItem('gridlist', 'Grid list', 'https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/GridList.png', 'snippets/documentation/gridlist.html'),
new DocumentationItem('materialwindow', 'Material window', 'https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/MaterialWindow.png', 'snippets/documentation/materialwindow.html'),
Expand All @@ -25,7 +25,7 @@ function AppViewModel(contentDivId, drawer) {
new DocumentationItem('search', 'Search', 'https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/PersistentSearch.png', 'snippets/documentation/search.html'),
new DocumentationItem('stepper', 'Stepper', 'https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/HorizontalStepper.png', 'snippets/documentation/stepper.html'),
new DocumentationItem('tabs', 'Tabs', 'https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/TabControl1.png', 'snippets/documentation/tabs.html'),
new DocumentationItem('textboxsuggestions', 'Text box suggestions', null, 'snippets/documentation/textboxsuggestions.html')
new DocumentationItem('textboxsuggestions', 'Text box suggestions', 'https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/TextBoxSuggestions.png', 'snippets/documentation/textboxsuggestions.html')
];

self.goToNavigationItem = function (navigationItem) {
Expand Down
85 changes: 83 additions & 2 deletions docs/snippets/documentation/autocomplete.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,85 @@
<div>
<h1>Autocomplete</h1>
Documentation under construction
</div>
<p>
The following predefined styles are available:
<ul>
<li><code>MaterialDesignAutocomplete</code></li>
<li><code>MaterialDesignAutocompleteDense</code></li>
</ul>
</p>

<h2>Screenshots</h2>
<img src="https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/Autocomplete.png" alt="Autocomplete" />
<h2>Code example</h2>

<p>Item template</p>
<pre class="language-markup"><code class="language-markup">
&lt;DataTemplate x:Key="itemTemplate">
&lt;DockPanel>
&lt;md:PackIcon DockPanel.Dock="Left" Kind="{Binding Path=Icon}" Width="24" Height="24" VerticalAlignment="Center" SnapsToDevicePixels="True" />
&lt;TextBlock FontSize="14" Text="{Binding Path=Name}" VerticalAlignment="Center" Margin="24,0,0,0" />
&lt;/DockPanel>
&lt;/DataTemplate>
</code></pre>

<p>Autocomplete control</p>
<pre class="language-markup"><code class="language-markup">
&lt;mde:Autocomplete Style="{StaticResource MaterialDesignAutocomplete}"
AutocompleteSource="{Binding Path=AutocompleteSource}"
Hint="Which OS?"
Margin="0,16,0,0"
ItemTemplate="{StaticResource itemTemplate}" />
</code></pre>

<p>Autocomplete data source</p>
<pre class="language-markup"><code class="language-markup">
public class AutocompleteViewModel : ViewModel
{
private IAutocompleteSource _autocompleteSource;

public IAutocompleteSource AutocompleteSource
{
get => _autocompleteSource;
}

public AutocompleteViewModel() : base()
{
_autocompleteSource = new OperatingSystemAutocompleteSource();
}
}

public class OperatingSystemItem
{
public PackIconKind Icon { get; set; }
public string Name { get; set; }
public OperatingSystemItem() { }
}

public class OperatingSystemAutocompleteSource : IAutocompleteSource
{
private List<OperatingSystemItem> _operatingSystemItems;

public OperatingSystemAutocompleteSource()
{
_operatingSystemItems = new List<OperatingSystemItem>()
{
new OperatingSystemItem() { Icon = PackIconKind.MicrosoftWindows, Name = "Windows 7" },
new OperatingSystemItem() { Icon = PackIconKind.MicrosoftWindows, Name = "Windows 8" },
new OperatingSystemItem() { Icon = PackIconKind.MicrosoftWindows, Name = "Windows 8.1" },
new OperatingSystemItem() { Icon = PackIconKind.MicrosoftWindows, Name = "Windows 10" }
};
}

public IEnumerable Search(string searchTerm)
{
searchTerm = searchTerm ?? string.Empty;
searchTerm = searchTerm.ToLower();

return _operatingSystemItems.Where(item => item.Name.ToLower().Contains(searchTerm));
}
}
</code></pre>
<script type="text/javascript">
appViewModel.prepareCodeSnippets();
</script>
</div>
83 changes: 82 additions & 1 deletion docs/snippets/documentation/busyoverlay.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,85 @@
<div>
<h1>Busy overlay</h1>
Documentation under construction
<p>
The following predefined styles are available:
<ul>
<li><code>MaterialBusyOverlayCircular</code></li>
<li><code>MaterialBusyOverlayCircularProgress</code></li>
<li><code>MaterialBusyOverlayLinear</code></li>
<li><code>MaterialBusyOverlayLinearProgress</code></li>
</ul>
</p>

<h2>Screenshots</h2>
<img src="https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/BusyOverlay.png" alt="Busy overlay" />

<h2>Code example</h2>

<p>Busy overlay control</p>
<pre class="language-markup"><code class="language-markup">
&lt;mde:BusyOverlay IsBusy="{Binding Path=IsBusy}"
Progress="{Binding Path=Progress}"
Style="{StaticResource MaterialBusyOverlayCircular}" />
</code></pre>

<p>Busy overlay show and progress bindings</p>
<pre class="language-markup"><code class="language-markup">
public class BusyOverlayViewModel : ViewModel
{
private bool _isBusy;
public bool IsBusy
{
get => _isBusy;
set
{
_isBusy = value;
OnPropertyChanged(nameof(IsBusy));
}
}

private int _progress;
public int Progress
{
get => _progress;
set
{
_progress = value;
OnPropertyChanged(nameof(Progress));
}
}

public BusyOverlayViewModel() : base()
{
_isBusy = false;
_progress = 0;
}

public async Task BeBusyAsync()
{
try
{
Progress = 0;
IsBusy = true;

//Simulate work and update progress
await Task.Run(async () =>
{
int progress = 0;

while (progress < 100)
{
await Task.Delay(250);

progress += 10;
Progress = progress;
}
});
}
finally
{
IsBusy = false;
}
}
}
</code></pre>
</div>
86 changes: 82 additions & 4 deletions docs/snippets/documentation/search.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,82 @@
<div>
<h1>Search</h1>
Documentation under construction
</div>
<div>
<h1>Persistent search</h1>
<p>
The following predefined styles are available:
<ul>
<li><code>MaterialDesignPersistentSearch</code></li>
<li><code>MaterialDesignPersistentSearchDense</code></li>
</ul>
</p>

<h2>Screenshots</h2>
<img src="https://raw.githubusercontent.com/spiegelp/MaterialDesignExtensions/master/screenshots/PersistentSearch.png" alt="Persistent search" />

<h2>Code example</h2>

<p>Persistent search control</p>
<pre class="language-markup"><code class="language-markup">
&lt;mde:PersistentSearch
Margin="8"
VerticalAlignment="Top"
SearchSuggestionsSource="{Binding SearchSuggestionsSource}" />
</code></pre>

<p>Persistent search data source</p>
<pre class="language-markup"><code class="language-markup">
public class SearchViewModel : ViewModel
{
public ISearchSuggestionsSource SearchSuggestionsSource
{
get => new OperatingSystemsSearchSuggestionsSource();
}
}

public class OperatingSystemsSearchSuggestionsSource : ISearchSuggestionsSource
{
private List<string> _operatingSystems;

public OperatingSystemsSearchSuggestionsSource()
{
_operatingSystems = new List<string>
{
"Windows 7",
"Windows 8",
"Windows 8.1",
"Windows 10"
};
}

public IList<string> GetAutoCompletion(string searchTerm)
{
return _operatingSystems.Where(os => os.ToLower().Contains(searchTerm.ToLower())).ToList();
}

public IList<string> GetSearchSuggestions()
{
return new List<string> { "Windows 10", "Windows 8.1" };
}
}
</code></pre>

<h2>Custom icons</h2>

<p>Make sure to include this namespace</p>
<pre class="language-markup"><code class="language-markup">
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
</code></pre>

<p>Set your desired icons like this</p>
<pre class="language-markup"><code class="language-markup">
&lt;mde:PersistentSearch
Margin="8"
VerticalAlignment="Top"
SearchSuggestionsSource="{Binding SearchSuggestionsSource}"
SearchIcon="{x:Static md:PackIconKind.PrinterSearch}"
CancelIcon="{x:Static md:PackIconKind.BellCancel}"
ClearIcon="{x:Static md:PackIconKind.CircleArrows}" />
</code></pre>

<script type="text/javascript">
appViewModel.prepareCodeSnippets();
</script>
</div>
Loading

0 comments on commit 4298064

Please sign in to comment.