Đang chuẩn bị liên kết để tải về tài liệu:
Apress-Visual CSharp 2010 Recipes A Problem Solution Approach_10
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
GetTemplateChild to find the button defined by its actual template. If this exists, it adds an event handler to the button’s Click event. The code for the control is as follows: using using using using System.Windows; System.Windows.Controls; System.Windows.Markup; Microsoft.Win32; | CHAPTER 17 WINDOWS PRESENTATION FOUNDATION GetTemplateChild to find the button defined by its actual template. If this exists it adds an event handler to the button s Click event. The code for the control is as follows using System.Windows using System.Windows.Controls using System.Windows.Markup using Microsoft.Win32 namespace Apress.VisualCSharpRecipes.Chapter17 TemplatePart Name PART_Browse Type typeof Button ContentProperty FileName public class FileInputControl Control static FileInputControl r DefaultStyleKeyProperty.OverrideMetadata typeof FileInputControl new FrameworkPropertyMetadata typeof FileInputControl public override void OnApplyTemplate base.OnApplyTemplate Button browseButton base.GetTemplateChild PART_Browse as Button if browseButton null browseButton.Click new RoutedEventHandler browseButton_Click void browseButton_Click object sender RoutedEventArgs e OpenFileDialog dlg new OpenFileDialog if dlg.ShowDialog true this.FileName dlg.FileName public string FileName get . return string GetValue FileNameProperty 830 CHAPTER 17 WINDOWS PRESENTATION FOUNDATION set SetValue FileNameProperty value public static readonly Dependencyproperty FileNameProperty DependencyProperty.Register FileName typeof string typeof FileInputControl The default style and control template for FileInputControl is in a ResourceDictionary in the Themes subfolder and is merged into the Generic ResourceDictionary. The XAML for this style is as follows ResourceDictionary xmlns http schemas.microsoft.com winfx 2006 xaml presentation xmlns x http schemas.microsoft.com winfx 2006 xaml xmlns local clr-namespace Apress.VisualCSharpRecipes.Chapter17 assembly Style TargetType x Type local FileInputControl Setter Property Template Setter.Value ControlTemplate TargetType x Type local FileInputControl Border Background TemplateBinding Background BorderBrush TemplateBinding BorderBrush BorderThickness TemplateBinding BorderThickness DockPanel Button x Name PART_Browse DockPanel.Dock Right .