mirror of https://github.com/icsharpcode/ILSpy.git
6 changed files with 209 additions and 1 deletions
@ -0,0 +1,121 @@
@@ -0,0 +1,121 @@
|
||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
|
||||
namespace ICSharpCode.ILSpy.Controls |
||||
{ |
||||
public class SearchBox : TextBox |
||||
{ |
||||
static SearchBox() { |
||||
DefaultStyleKeyProperty.OverrideMetadata( |
||||
typeof(SearchBox), |
||||
new FrameworkPropertyMetadata(typeof(SearchBox))); |
||||
} |
||||
|
||||
#region Dependency properties
|
||||
|
||||
public static DependencyProperty WatermarkTextProperty = DependencyProperty.Register("WatermarkText", typeof(string), typeof(SearchBox)); |
||||
|
||||
public static DependencyProperty WatermarkColorProperty = DependencyProperty.Register("WatermarkColor", typeof(Brush), typeof(SearchBox)); |
||||
|
||||
public static DependencyProperty HasTextProperty = DependencyProperty.Register("HasText", typeof(bool), typeof(SearchBox)); |
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public string WatermarkText { |
||||
get { return (string)GetValue(WatermarkTextProperty); } |
||||
set { SetValue(WatermarkTextProperty, value); } |
||||
} |
||||
|
||||
public Brush WatermarkColor { |
||||
get { return (Brush)GetValue(WatermarkColorProperty); } |
||||
set { SetValue(WatermarkColorProperty, value); } |
||||
} |
||||
|
||||
public bool HasText { |
||||
get { return (bool)GetValue(HasTextProperty); } |
||||
private set { SetValue(HasTextProperty, value); } |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region Handlers
|
||||
|
||||
private void IconBorder_MouseLeftButtonUp(object obj, MouseButtonEventArgs e) { |
||||
if (this.HasText) |
||||
this.Text = string.Empty; |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
protected override void OnTextChanged(TextChangedEventArgs e) { |
||||
base.OnTextChanged(e); |
||||
|
||||
HasText = this.Text.Length > 0; |
||||
} |
||||
|
||||
protected override void OnLostFocus(RoutedEventArgs e) |
||||
{ |
||||
if (!HasText) { |
||||
Label wl = (Label)GetTemplateChild("WatermarkLabel"); |
||||
wl.Visibility = Visibility.Visible; |
||||
} |
||||
|
||||
base.OnLostFocus(e); |
||||
} |
||||
|
||||
protected override void OnGotFocus(RoutedEventArgs e) |
||||
{ |
||||
if (!HasText) { |
||||
Label wl = (Label)GetTemplateChild("WatermarkLabel"); |
||||
wl.Visibility = Visibility.Hidden; |
||||
} |
||||
|
||||
base.OnGotFocus(e); |
||||
} |
||||
|
||||
public override void OnApplyTemplate() { |
||||
base.OnApplyTemplate(); |
||||
|
||||
Border iconBorder = GetTemplateChild("PART_IconBorder") as Border; |
||||
if (iconBorder != null) { |
||||
iconBorder.MouseLeftButtonUp += IconBorder_MouseLeftButtonUp; |
||||
} |
||||
} |
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e) |
||||
{ |
||||
if (e.Key == Key.Escape) { |
||||
this.Text = string.Empty; |
||||
} else { |
||||
base.OnKeyDown(e); |
||||
} |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,70 @@
@@ -0,0 +1,70 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:local="clr-namespace:ICSharpCode.ILSpy.Controls"> |
||||
|
||||
<Style x:Key="{x:Type local:SearchBox}" TargetType="{x:Type local:SearchBox}"> |
||||
<Setter Property="Background" Value="White" /> |
||||
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" /> |
||||
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" /> |
||||
<Setter Property="BorderThickness" Value="1" /> |
||||
<Setter Property="SnapsToDevicePixels" Value="True" /> |
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/> |
||||
<Setter Property="Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="{x:Type local:SearchBox}"> |
||||
<Border x:Name="Border" |
||||
Cursor="IBeam" |
||||
Background="{TemplateBinding Background}" |
||||
BorderBrush="{TemplateBinding BorderBrush}" |
||||
BorderThickness="{TemplateBinding BorderThickness}"> |
||||
<Grid x:Name="LayoutGrid"> |
||||
<Grid.ColumnDefinitions> |
||||
<ColumnDefinition Width="*" /> |
||||
<ColumnDefinition Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualHeight}" /> |
||||
</Grid.ColumnDefinitions> |
||||
<ScrollViewer Margin="2" x:Name="PART_ContentHost" Grid.Column="0" /> |
||||
<Label x:Name="WatermarkLabel" |
||||
Margin="2" |
||||
Grid.Column="0" |
||||
Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=WatermarkColor}" |
||||
Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=WatermarkText}" |
||||
Padding="2,0,0,0" |
||||
FontStyle="Italic" /> |
||||
<Border x:Name="PART_IconBorder" |
||||
Grid.Column="1" |
||||
BorderThickness="1" |
||||
VerticalAlignment="Stretch" |
||||
HorizontalAlignment="Stretch" |
||||
BorderBrush="Transparent" |
||||
Background="Transparent"> |
||||
<Image x:Name="SearchIcon" |
||||
Cursor="Arrow" |
||||
Stretch="None" |
||||
Width="12" |
||||
Height="12" |
||||
HorizontalAlignment="Center" |
||||
VerticalAlignment="Center" |
||||
ToolTip="Search" |
||||
Source="pack://application:,,,/ILSpy;component/images/search.png" /> |
||||
</Border> |
||||
</Grid> |
||||
</Border> |
||||
<ControlTemplate.Triggers> |
||||
<Trigger Property="HasText" Value="True"> |
||||
<Setter Property="Visibility" TargetName="WatermarkLabel" Value="Hidden" /> |
||||
</Trigger> |
||||
<MultiTrigger> |
||||
<MultiTrigger.Conditions> |
||||
<Condition Property="HasText" Value="True" /> |
||||
</MultiTrigger.Conditions> |
||||
<Setter Property="Source" |
||||
TargetName="SearchIcon" |
||||
Value="pack://application:,,,/ILSpy;component/images/clearsearch.png" /> |
||||
<Setter Property="ToolTip" TargetName="SearchIcon" Value="Clear"/> |
||||
</MultiTrigger> |
||||
</ControlTemplate.Triggers> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
</ResourceDictionary> |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 510 B |
Loading…
Reference in new issue