Saturday 15 August 2015

c# - WPF- Catch the clicking of a button that was added to a style (ListBoxItem) -


I added a button in a template for ListBoxItem. I want to know how to click for button (Listbox item Do not select).

The button just clicks ok on the UI, but I do not know how to wire the code so that I can hold it.

I tried to use it:

& lt; EventSetter Event = "Click" handler = "button_click" & gt; & Lt; / EventSetter & gt;

But it seems that he wanted to be on ListBoxItem.

  & lt; Window x: Class = "WIAssistant.Main" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/ Xaml "title =" my app "height =" 587 "width =" 1246 "name =" mainform "fontism =" 14 "& gt; & Lt; Window.Resources & gt; & Lt; Style x: key = "checkbox list" target type = "list box" & gt; & Lt; Style.Resources & gt; & Lt; Style TargetType = "ListBoxItem" & gt; & Lt; Setter Estates = "Template" & gt; & Lt; Setter.Value & gt; & Lt; ControlTemplate TargetType = "ListBoxItem" & gt; & Lt; Grid ScrollViewer.CanContentScroll = "True" margin = "2" & gt; & Lt; Grid.ColumnDefinitions & gt; & Lt; Column width = "Auto" /> & Lt; Column width = "Auto" /> & Lt; Column width = "Auto" /> & Lt; Columns Definition / & gt; & Lt; /Grid.ColumnDefinitions> & Lt; Checkbox vertical element = "center" iiscaphed = "{binding assists, relative saras = {relative values ​​typical parent}, mode = twoway}" /> & Lt; Text Block Vertical Element = "Center" Grid. Column = "1" margin = "5,0,5,0" text = "{binding id}" /> & Lt; Text Block Vertical Element = "Center" Grid. Column = "2" margin = "5,0,5,0" text = "{binding title}" /> & Lt; Button horizontal tracing = "right" grid. Column = "3" margin = "5,0,5,0" width = "25" & gt; - & amp; Gt; & Lt; / Button & gt; & Lt; / Grid & gt; & Lt; / ControlTemplate & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Style & gt; & Lt; /Style.Resources> & Lt; Setter Property = "ItemPanel" & gt; & Lt; Setter.Value & gt; & Lt; ItemsPanelTemplate & gt; & Lt; WrapPanel Orientation = "Vertical" /> & Lt; / ItemsPanelTemplate & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; Setter Property = "BorderTitches" value = "0" /> & Lt; Setter property = "background" value = "transparent" /> & Lt; / Style & gt; & Lt; /Window.Resources> ... liters (which later into a code in a grid) and; ListBox SelectionMode = "Multiple" style = "{StaticResource CheckBoxListStyle}" name = "lstQueryResults" SelectionChanged = "lstQueryResults_SelectionChanged" & gt; & Lt; / ListBox & gt;  

Any way to capture clicks for the button will be appreciated. (Note that simply adding an click event on the button calls an error to use a EventSetter .

"post-text" itemprop = "text">

event handler To keep the style in window resources, try the following:

  & lt; window; Resources & gt; & gt; DataTemplate x: key = "ListBoxItemTemplate" & gt; Grid ScrollViewer.CanContentScroll = "Right" margin = "2">  
ColumnDefinition width = "Automated" /> gt; & lt; & lt; ; ColumnDefinition wide E = "Automatic" /> ColumnDefinition width = "Automated" /> TextBlock VerticalAlignment = "Center" Grid.Column = "1" margin = "5,0,5,0" text = "{ID}" / & Gt binding; & lt; TextBlow CK vertical alignment = "center" grid.column = "2" margin = "5,0,5,0" text = "{binding title}" /> & Lt; Button HorizontalAlignment = "right" Grid.Column = "3" margin = "5,0,5,0" width = "25" = "Button_Click" & gt; - & amp; Gt; & Lt; / Button & gt; & Lt; / Grid & gt; & Lt; / DataTemplate & gt; & Lt; /Window.Resources>

+

  & lt; List box item template = "{static resource listbox} template") & gt;  

The event setter also works in the template, but apparently the design scene in VS stops working.


No comments:

Post a Comment