c# - Silverlight. Bind style items to datacontext -
I have a custom style button and I want to paste the style item into the button datacontext. How to do this?
My attempts:
& lt; UserControl.Resources & gt; & Lt; Style x: Key = "ButtonStyle1" TargetType = "Button" & gt; & Lt; Setter Estates = "Template" & gt; & Lt; Setter.Value & gt; & Lt; ControlTemplate TargetType = "Button" & gt; & Lt; Grid & gt; & Lt; TextBlock TextWrapping = "wrap" text = "{binding reference text}" datacontax = "{TemplateBinding DataContext}" /> & Lt; / Grid & gt; & Lt; / ControlTemplate & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Style & gt; & Lt; /UserControl.Resources> & Lt; Grid X: Name = "Layouts" background = "White" & gt; & Lt; Button content = "button" height = "131" width = "103" horizontal alignment = "left" workspaceElement = "top" click = "button_link" / & gt; & Lt; Button x: name = "button" style = "{static resource button button 1}" margin = "165,86,0,0" /> & Lt; / Grid & gt;
C # code
public partial class manpage: usercontrol {public manpage ()} {InitializeComponent (); } Private Zero Button_Click (Object Sender, System.Windows.RoutedEventArgs e) {button.DataContext = New Test () {ContextText = "TextFromContext"}; Button.UpdateLayout (); }} Public square test {public string context text {get; Set;}}
Umm .. this is what you are searching for : -
& lt; Button x: name = "button" content = "{binding reference text}" style = "{static resource button button 1}" margin = "165, 86,0,0" />
I'm almost embarrassed to submit it, it looks like 101.
Comments
Post a Comment