http://www.cnblogs.com/ManMonth/archive/2011/08/30/2159956.html
說明
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace ENPOT.Distribution.Management.View
{
public class UcSearchPanel : ContentControl
{
private Button _btnRset;
private Button _btnSearch;
static UcSearchPanel()
{
DefaultStyleKeyProperty.GetMetadata(typeof(UcSearchPanel));
}
// Methods
public UcSearchPanel()
{
base.DefaultStyleKey = typeof(UcSearchPanel);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
this.btnRset = base.GetTemplateChild("btnRset") as Button;
this.btnSearch = base.GetTemplateChild("btnSearch") as Button;
}
private Button btnRset
{
get
{
return this._btnRset;
}
set
{
if (this._btnRset != null)
{
this._btnRset.Click -= new RoutedEventHandler(this.ResetButton_Click);
}
this._btnRset = value;
if (this._btnRset != null)
{
this._btnRset.Click += new RoutedEventHandler(this.ResetButton_Click);
}
}
}
private Button btnSearch
{
get
{
return this._btnSearch;
}
set
{
if (this._btnSearch != null)
{
this._btnSearch.Click -= new RoutedEventHandler(this.SearchButton_Click);
}
this._btnSearch = value;
if (this._btnSearch != null)
{
this._btnSearch.Click += new RoutedEventHandler(this.SearchButton_Click);
}
}
}
private void ResetButton_Click(object sender, RoutedEventArgs e)
{
if (this.ResetEventHandler != null)
{
this.ResetEventHandler(sender, e);
}
}
private void SearchButton_Click(object sender, RoutedEventArgs e)
{
if (this.SearchEventHandler != null)
{
this.SearchEventHandler(sender, e);
}
}
public event EventHandler SearchEventHandler;
public event EventHandler ResetEventHandler;
}
}
<!--搜尋控制項-->
<Style TargetType="uc:UcSearchPanel">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="uc:UcSearchPanel">
<Grid x:Name="LayoutRoot">
<Border Grid.Column="0" CornerRadius="2" BorderBrush="#95A4B1" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<!--提示-->
<StackPanel Grid.Row="0" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Stretch"
Background="{StaticResource ModuleSelectorBackgroundBrush}"
Orientation="Horizontal">
<StackPanel.Effect>
<DropShadowEffect Color="Gray" ShadowDepth="0" BlurRadius="2" Opacity="0.6"/>
</StackPanel.Effect>
<TextBlock Text="{StaticResource UcAuditSaleOrder_Search}" VerticalAlignment="Center" Margin="5,0,0,0"/>
</StackPanel>
<ContentPresenter Grid.Row="1" VerticalAlignment="Top"
HorizontalAlignment="Stretch" />
<!--按鈕-->
<Button x:Name="btnRset" Grid.Row="2"
Style="{StaticResource ToolButton}"
HorizontalAlignment="RIght"
VerticalAlignment="Top"
Margin="10,10,90,20"
>
<StackPanel Orientation="Horizontal" >
<Image Width="16"
Height="16"
Source="/ENPOT.Distribution.Management;component/Resources/Images/rest.png"
Margin="0,0,3,0"/>
<TextBlock Text="{StaticResource UcAuditSaleOrder_Rset}"/>
</StackPanel>
</Button>
<Button x:Name="btnSearch" Grid.Row="2"
Style="{StaticResource ToolButton}"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,10,10,20"
>
<StackPanel Orientation="Horizontal" >
<Image Width="16"
Height="16"
Source="/ENPOT.Distribution.Management;component/Resources/Imagesarch.png"
Margin="0,0,3,0"/>
<TextBlock Text="{StaticResource UcAuditSaleOrder_SearchBtn}"/>
</StackPanel>
</Button>
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--搜尋控制項End-->