c# - Checkbox checked event not firing in wpf -


hi in form(adminentitylist.xaml) file contains code below

<resourcedictionary xmlns:local="clr-namespace:iwatch.administration"                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"                   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"                   mc:ignorable="d"                   xmlns:my="clr-namespace:iwatch.uilibrary;assembly=uilibrary"                   xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"                  xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"                   xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"                  xmlns:cmd="clr-namespace:iwatch.uilibrary;assembly=uilibrary"                  x:class="adminentitylist">      <controltemplate x:key="addimgbtntemplate" targettype="button">         <grid>             <image name="normal" source="/uilibrary;component/themes/default/images/add.png" opacity="1.0" height="18" width="18"/>         </grid>         <controltemplate.triggers>             <trigger property="ispressed" value="true">                 <setter targetname="normal" property="opacity" value="0.5"/>             </trigger>             <trigger property="isenabled" value="false">                 <setter targetname="normal" property="opacity" value="0.2"/>             </trigger>         </controltemplate.triggers>     </controltemplate>      <controltemplate x:key="delimgbtntemplate" targettype="button">         <grid>             <image name="normal" source="/uilibrary;component/themes/default/images/delete.png" opacity="1.0" height="18" width="18"/>         </grid>         <controltemplate.triggers>             <trigger property="ispressed" value="true">                 <setter targetname="normal" property="opacity" value="0.5"/>             </trigger>             <trigger property="isenabled" value="false">                 <setter targetname="normal" property="opacity" value="0.2"/>             </trigger>         </controltemplate.triggers>     </controltemplate>          <style targettype="{x:type local:adminentitylist}">         <setter property="fontfamily" value="calibri"/>         <setter property="dx:thememanager.themename" value="office2007black"/>         <setter property="template" >             <setter.value>                  <controltemplate targettype="{x:type local:adminentitylist}">                     <dockpanel>                         <dockpanel dockpanel.dock="top">                             <stackpanel name="stpfilter" orientation="horizontal" horizontalalignment="left" margin="5">                                 <contentcontrol x:name="filtercriteriaarea" contenttemplate="{templatebinding filtercriteriaarea}"/>                             </stackpanel>                            <stackpanel name="stpcountry" orientation="horizontal" horizontalalignment="right" margin="5" >                                 <label  content="select country" name="lblcountry" style="{staticresource lblnormal}" margin="10,0,5,7" horizontalalignment="stretch" verticalalignment="bottom" visibility="collapsed"/>                                 <combobox name="cbcountry"  width="170" style="{staticresource ddlnormal}"  selectedvalue="{binding countrykey,mode=twoway}" horizontalalignment="left" verticalalignment="top" margin="5,2,10,0" visibility="collapsed"/>                                 <button content="filter" name="btnfilter" width="70" height="23" margin="0,0,10,0" visibility="collapsed"/>                                                     </stackpanel>                             <stackpanel name="actinact" orientation="horizontal" horizontalalignment="left" margin="5">                                 <checkbox name="chkactive" height="18" content="active" checked="chkactive_checked"></checkbox>                                 <checkbox name="chkinactive" height="18" content="in-active"/>                             </stackpanel>                             <stackpanel name="stpadddel" orientation="horizontal" horizontalalignment="right" margin="5">                                 <button name="btnadd"  height="20" width="20" margin="5,0" template="{staticresource addimgbtntemplate}" />                                 <button name="btndel" height="20" width="20" margin="5,0" template="{staticresource delimgbtntemplate}" />                             </stackpanel>                          </dockpanel>                         <dockpanel name="amldp">                             <dxg:gridcontrol name="genericgrid" autopopulatecolumns="true"  showborder="false"                            designtimedatasourcerowcount="50"  datasource="{binding}"                           padding="0" margin="0,0,0,0" ismanipulationenabled="true" dx:thememanager.themename="cpcegridtheme">                                 <dxg:gridcontrol.resources>                                     <resourcedictionary x:key="cpcegridtheme" source="/uilibrary;component/themes/default/styles/datagrid/cpcegridtheme.xaml" />                                 </dxg:gridcontrol.resources>                                 <dxg:gridcontrol.view>                                         <dxg:tableview x:name="tblgeneric" multiselectmode="row" allowgrouping="true" cliptobounds="true"  autowidth="true"                                          showgrouppanel="false" showhorizontallines="true" showverticallines="false" allowmovecolumntodroparea="false" allowdrop="false"                                                                                                                                           isgrouppanelmenuenabled="false"  allowediting="false" navigationstyle="cell" margin="0"                                          grouprowstyle="{staticresource oddevenrowstyle}" virtualizingstackpanel.isvirtualizing="true"                                          virtualizingstackpanel.virtualizationmode="standard" allowhorizontalscrollingvirtualization="true"                                          rowstyle="{staticresource oddevenrowstyle}" cellstyle="{staticresource focusedcellstyle}">                                         <dxg:tableview.rowcellmenucustomizations>                                             <dxb:barbuttonitem name="ctmview" isvisible="false"  content="view" command="{x:static cmd:customcommands.view}" />                                             <dxb:barbuttonitem name="ctmedit" isvisible="true"  content="edit" command="{x:static cmd:customcommands.edit}" />                                             <dxb:barbuttonitem name="ctmmiq" isvisible="false"  content="manage interview questions" command="{x:static cmd:customcommands.manageinterviewquestions}" />                                             <dxb:barbuttonitem name="ctmactivate" isvisible="false" content="activate" command="{x:static cmd:customcommands.activate}" />                                             <dxb:barbuttonitem name="ctmcopyinterviewtype" isvisible="false" content="copy interview type" command="{x:static cmd:customcommands.copyinterviewtype}" />                                             <dxb:barbuttonitem name="ctmassigninvgroup" isvisible="false" content="assign investigative group" command="{x:static cmd:customcommands.assigninvestigativegroup}" />                                             <dxb:barbuttonitem name="ctmcopyselected" isvisible="false" content="copy selected" command="{x:static cmd:customcommands.copyinterviewtemplate}" />                                         </dxg:tableview.rowcellmenucustomizations>                                     </dxg:tableview>                                 </dxg:gridcontrol.view>                                 <dxg:gridcontrol.commandbindings>                                     <commandbinding x:name="cmdedit" command="{x:static cmd:customcommands.edit}" />                                     <commandbinding x:name="cmdview" command="{x:static cmd:customcommands.view}" />                                     <commandbinding x:name="cmdmiq" command="{x:static cmd:customcommands.manageinterviewquestions}" />                                     <commandbinding x:name="cmdactivate" command="{x:static cmd:customcommands.activate}" />                                     <commandbinding x:name="cmdcopyinterviewtype" command="{x:static cmd:customcommands.copyinterviewtype}" />                                     <commandbinding x:name="cmdassigninvestigativegroup" command="{x:static cmd:customcommands.assigninvestigativegroup}" />                                     <commandbinding x:name="cmdcopyselected" command="{x:static cmd:customcommands.copyinterviewtemplate}" />                                  </dxg:gridcontrol.commandbindings>                             </dxg:gridcontrol>                         </dockpanel>                     </dockpanel>                 </controltemplate>             </setter.value>         </setter>     </style>  </resourcedictionary> 

in above code created checkbox checked event checked="chkactive_checked"

private void chkactive_checked(object sender, routedeventargs e)         {          } 

but event not firing , getting error

error 14 'adminentitylist' not contain definition 'chkactive_checked' , no extension method 'chkactive_checked' accepting first argument of type 'adminentitylist' found (are missing using directive or assembly reference?)

please me problem...

here simple example:

<window x:class="checkboxcheckedcommand.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"> <grid>     <checkbox content="case sensitive" command="{binding checkedcommand}"/> </grid> 

codebehind:

public partial class mainwindow : window {     public viewmodel vm { get; set; }      public mainwindow()     {         initializecomponent();          vm = new viewmodel();         this.datacontext = vm;     } } 

viewmodel:

public class viewmodel {     public icommand checkedcommand { get; set; }      public viewmodel()     {         checkedcommand = new checkedcommand(this);     }      public void checkedhandler()     {         //todo - implement handler     } } 

and of course checked unchecked command:

public class checkedcommand : icommand {     private viewmodel _vm = null;     public checkedcommand(viewmodel _viewmodel)     {         _vm = _viewmodel;     }      public bool canexecute(object parameter)     {         return true;     }      public event eventhandler canexecutechanged;      public void execute(object parameter)     {         _vm.checkedhandler();     } } 

let me know if need more details, maybe parameter has sent view , received handler..

i see easy , normal flow mvvm. have instance/static method issue right there.. try above approach, in opinion cleared , helps decouple things.

oh, forgot say, command="{binding checkedcommand}" , both applicable checked , unchecked events.

update 1

this can codebehind:

public partial class mainwindow : window {     public bool ischecked     {         { return (bool)getvalue(ischeckedproperty); }         set { setvalue(ischeckedproperty, value); }     }      // using dependencyproperty backing store ischecked.  enables animation, styling, binding, etc...     public static readonly dependencyproperty ischeckedproperty =         dependencyproperty.register("ischecked", typeof(bool), typeof(mainwindow), new propertymetadata(false, new propertychangedcallback(propertychanged)));       private static void propertychanged(dependencyobject obj, dependencypropertychangedeventargs e)     {         //textbox.scrolltoend(); //an object reference required non-static field.          mainwindow localwindow = (mainwindow)obj;         console.writeline(localwindow.teststring);     }      public string teststring { get; set; }      public mainwindow()     {         initializecomponent();          teststring = "test";         this.datacontext = this;     }  } 

and checkbox definition now:

<checkbox content="case sensitive" ischecked="{binding ischecked}"/> 

you define dependencyproperty name ischecked. each time check or uncheck it, callback method defined there called. , may see example on how access instance field static method. luck!


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -