I created a form template for windows, and named "WindowStyle1":
& lt; Style x: key = "WindowStyle1" TargetType = "{x: type window}" & gt; & Lt; Setter Property = "Foreground" Value = "{DynamicResource {x: Static System Calculators. WindowTextBrushKey}}" /> & Lt; Setter property = "background" value = "{DynamicResource {x: static system calculators. WindowBrushKey}}" /> & Lt; Setter Estates = "Template" & gt; & Lt; Setter.Value & gt; & Lt; ControlTemplate TargetType = "{x: type window}" & gt; & Lt; Border height = "auto" width = "auto" background = "# ff 27c986" margin = "10" & gt; & Lt; Border.Effect & gt; & Lt; DropShadeEffahed ShadowDown = "0" direction = "180" Opacity = "0.52" Blurardius = "10" /> & Lt; /Border.Effect> & Lt; Grid Loaded = "On-Wide Loaded" & gt; & Lt; Grid.ColumnDefinitions & gt; & Lt; ColumnDefinition / & gt; & Lt; Column width = "94" /> & Lt; /Grid.ColumnDefinitions> & Lt; Grid.RowDefinitions & gt; & Lt; Roadfinion height = "38" /> & Lt; RowDefinition / & gt; & Lt; /Grid.RowDefinitions> & Lt; BorderBrush = "{TemplateBinding BorderBrush}" BorderThickness = "{TemplateBinding BorderThickness}" background = "{TemplateBinding Background}" Grid.RowSpan = "1" Grid.Row = "1" Grid.ColumnSpan = "2" & gt; & Lt; AdornerDecorator & gt; & Lt; ContentPresenter / & gt; & Lt; / AdornerDecorator & gt; & Lt; / Border & gt; & Lt; Click on the button = "minimize_window" X: name = "btn_window_minimize" Grid.Column = "1" HorizontalAlignment = "left" margin = "4.565,9.5,0,0" VerticalAlignment = "top" width = "20" height = "19.96" style = "{dynamic resource button system_windomist syses}" bordertechnines = "1" /> & Lt; Click on the button = "maximize_window" X: name = "btn_window_maximize" Grid.Column = "1" HorizontalAlignment = "left" margin = "34.565,9.5,0,0" VerticalAlignment = "top" width = "20" height = "19.96" style = "{DynamicResource ButtonStyle_Windows_MaximumSize}" /> & Lt; Click on the button = "close_window" x: name = "btn_window_close" Grid.Column = "1" HorizontalAlignment = "left" margin = "64,9.5,0,0" VerticalAlignment = "top" width = "20" height = "19.96" style = "{DynamicResource ButtonStyle_Windows_Close}" /> & Lt; Grid MouseLeftButtonDown = "Window_MouseLeftButtonDown" HorizontalAlignment = "Muscles" Height = "38" VerticalAlignment = "Top" Background = "# FF27C986" & gt; & Lt; Label name = "lbl_title" content = "label" HorizontalAlignment = "left" margin = "0.998,0,0,0" VerticalAlignment = "top" FONTSIZE = "20" foreground = "white" /> & Lt; / Grid & gt; & Lt; / Grid & gt; & Lt; / Border & gt; & Lt; / ControlTemplate & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; Style.Triggers & gt; & Lt; Trigger Property = "ResizeMode" Value = "CanResizeWithGrip" & gt; & Lt; Setter property = "Template" value = "{static resource windatmeter}" /> & Lt; / Catalyst & gt; & Lt; /Style.Triggers> & Lt; / Style & gt;
And I tie it in the .xml file in the "Window.cs" category:
Namespace WpfApplication2 {partial squares window: ResourceDictionary {public Windows () {InitializeComponent (); }}}
But in my "Main Wondo. XML" button buttons can not be found.
Main question:
How to find label control that is defined in custom window style in wpf
Any ideas? I'm sorry for bad english!
You must do this in the event (or later) it has loaded.
Public Partial Class Main Window: Window {Public Key Window ()} {InitializeComponent (); Var label = Template.FindName ("lbl_title", as this label); Loaded + = MainVoloaded; } Zero MainWindow_Loaded (Object Sender, RoutedEventArgs E) {var label = Template.FindName ("lbl_title", as this label); }}
No comments:
Post a Comment