vb.net - event handler in a resources dictionary xaml -


i have written little code in vb.net:

first main window:

<window x:class="mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <window.resources>     <resourcedictionary>         <resourcedictionary.mergeddictionaries>             <resourcedictionary source="dictionary.xaml" />         </resourcedictionary.mergeddictionaries>     </resourcedictionary> </window.resources> <grid>     <button content="button1" height="23" horizontalalignment="left" margin="35,35,0,0" name="button1" verticalalignment="top" width="75" />     <button content="button2" height="23" horizontalalignment="left" margin="35,85,0,0" name="button2" verticalalignment="top" width="75" />     <stackpanel name="display" grid.row="1" grid.column="0" background="lightblue" margin="50,150,50,10"                 horizontalalignment="stretch" verticalalignment="stretch">         <contentcontrol name="content">          </contentcontrol>     </stackpanel> </grid> 

then dictionary:

<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:class="myresources"> <style  targettype="{x:type button}">     <eventsetter event="button.click" handler="click"/> </style> <datatemplate x:key="template1">     <grid>         <grid.rowdefinitions>             <rowdefinition/>         </grid.rowdefinitions>         <grid.columndefinitions>             <columndefinition/>         </grid.columndefinitions>         <textbox margin="10,50,0,0" horizontalalignment="center" verticalalignment="top" width="200" />         <button name="bt_1" content="test1" margin="10,10" horizontalalignment="right" verticalalignment="top"                  width="150" />     </grid> </datatemplate> <datatemplate x:key="template2">     <grid>         <grid.rowdefinitions>             <rowdefinition/>         </grid.rowdefinitions>         <grid.columndefinitions>             <columndefinition/>         </grid.columndefinitions>         <textbox margin="10,50,0,0" horizontalalignment="center" verticalalignment="top" width="200" />         <button name="bt_2" content="test2" margin="10,10" horizontalalignment="right" verticalalignment="top"                  width="150" />     </grid> </datatemplate> 

and class myresources manages code behind dictionary:

public class myresources private sub click(byval sender system.object, byval e system.windows.routedeventargs)     msgbox("hello") end sub 

end class

this code compiles properly, no problem. problem one:

  1. first when on mainwindow , click on button1 or button2, have msgbox("hello"). problem because want msgbox when click on button in dictionary, example bt_1 (the 1 content test1).

  2. in dictionary have added style , handler buttons of dictionary. want add specific handler each button in myresources class, possible?

typically, have in myresources class:

private sub click_one(byval sender system.object, byval e system.windows.routedeventargs)     msgbox("bt_1 clicked") end sub  private sub click_two(byval sender system.object, byval e system.windows.routedeventargs)     msgbox("bt_2 clicked") end sub 

but can't add handles bt_1...after methods..

i give answers. please, don't send me links similars threads have been evocated, have ridden lot of them , didn't me...

no can't that, because can't create dynamically event handler name in resource file. don't think xaml syntax can let that.

still need add event handlers manually, each , every button cant click event.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -