Last active
August 29, 2015 14:13
-
-
Save cucmberium/2e4be2eead9275787f9c to your computer and use it in GitHub Desktop.
SearchBox Suggestion to Top
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Windows.UI.Xaml; | |
using Windows.UI.Xaml.Controls; | |
using Windows.UI.Xaml.Controls.Primitives; | |
namespace Flantter.Cascade.Views.Controls | |
{ | |
public sealed class CustomSearchBox : SearchBox | |
{ | |
public CustomSearchBox() | |
{ | |
} | |
private Popup _Popup; | |
private ListView _ListView; | |
public bool SuggestionToTop | |
{ | |
get { return (bool)this.GetValue(SuggestionToTopProperty); } | |
set { this.SetValue(SuggestionToTopProperty, value); } | |
} | |
public static readonly DependencyProperty SuggestionToTopProperty = | |
DependencyProperty.RegisterAttached("SuggestionToTop", typeof(bool), | |
typeof(CustomSearchBox), null); | |
protected override void OnApplyTemplate() | |
{ | |
base.OnApplyTemplate(); | |
this._Popup = (Popup)GetTemplateChild("SearchSuggestionsPopup"); | |
this._ListView = (ListView)GetTemplateChild("SearchSuggestionsList"); | |
this._ListView.SizeChanged += SearchSuggestionsList_SizeChanged; | |
} | |
private void SearchSuggestionsList_SizeChanged(object sender, SizeChangedEventArgs e) | |
{ | |
if (_Popup == null || _ListView == null) | |
return; | |
if (SuggestionToTop) | |
{ | |
if (_Popup.VerticalAlignment == Windows.UI.Xaml.VerticalAlignment.Bottom) | |
_Popup.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top; | |
_Popup.Margin = new Thickness(0.0, -e.NewSize.Height, 0.0, -e.NewSize.Height); | |
} | |
else | |
{ | |
if (_Popup.VerticalAlignment == Windows.UI.Xaml.VerticalAlignment.Top) | |
_Popup.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom; | |
_Popup.Margin = new Thickness(0.0, 0.0, 0.0, 0.0); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment