Silverlight使用者控制項自訂,同事寫的例子目前自己還沒看懂,不過先留著

來源:互聯網
上載者:User

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-->

 

 

 

 

 

 

 

 

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.