c# - Caliburn.micro and a usercontrol click handler -


i have created simple user control, imagebutton

<usercontrol x:class="sampleapp.controls.imagebutton"              name="imagebuttoncontrol"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"              d:designheight="300"              d:designwidth="300"              mc:ignorable="d">     <button>         <grid>             <grid.rowdefinitions>                 <rowdefinition height="1*" />                 <rowdefinition height="6*" />                 <rowdefinition height="2*" />                 <rowdefinition height="1*" />             </grid.rowdefinitions>             <image grid.row="1" source="{binding elementname=imagebuttoncontrol, path=image}" verticalalignment="stretch" horizontalalignment="center" />             <textblock grid.row="2" text="{binding elementname=imagebuttoncontrol, path=text}" verticalalignment="stretch" horizontalalignment="center" />         </grid>     </button> </usercontrol> 

with code behind:

using system.windows; using system.windows.controls; using system.windows.media;  namespace sampleapp.controls {     /// <summary>     /// interaction logic imagebutton.xaml     /// </summary>     public partial class imagebutton : usercontrol     {         public imagebutton()         {             initializecomponent();         }          public string text         {             { return (string)getvalue(textproperty); }             set { setvalue(textproperty, value); }         }          public static readonly dependencyproperty textproperty =           dependencyproperty.register("text", typeof(string), typeof(imagebutton), new uipropertymetadata(""));          public imagesource image         {             { return (imagesource)getvalue(imageproperty); }             set { setvalue(imageproperty, value); }         }          public static readonly dependencyproperty imageproperty =            dependencyproperty.register("image", typeof(imagesource), typeof(imagebutton), new uipropertymetadata(null));      } } 

now want use in little sample application like

xmlns:controls="clr-namespace:sampleapp.controls"  <controls:imagebutton grid.row="1"                               grid.column="1"                               margin="2"                               image="/images/link.png"                               text="dosomething">             <i:interaction.triggers>                 <i:eventtrigger eventname="click">                     <cal:actionmessage methodname="dosomething" />                 </i:eventtrigger>             </i:interaction.triggers>         </controls:imagebutton> 

if give x:name, like

<controls:imagebutton x:name="dosomething"  

e.g. dosomething method dosomething name directly called when view shown, i.e. when active viewmodel contains button, click button (if normal button , not usercontrol, work way), button-click handler never called on clicking.

now tried add actionmessage seen above, not work either...

what wrong here?

that's because there no convention configured user control type. either add convention via conventionmanager (see http://caliburnmicro.codeplex.com/wikipage?title=all%20about%20conventions), or derive type button instead.

you not use custom user control , instead add image content property of button in view.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -