c# - Binding to Color property of Item in ListView doesn't work -


i have code. each item in listview includes label , checkbox elements. label represents title of binded lineseries item, checkbox binded isvisible property of lineseries item.

i want trigger set background property (of border element in checkbox controltemplate) color of lineseries element, when lineseries element visible. setting lightgray color works, changing isvisible property works, background of border not change.

  <listview name="mylistview"  horizontalalignment="left" height="253" margin="445,10,0,0" verticalalignment="top" width="72" itemssource="{binding path=model.series}">         <listview.itemtemplate>             <datatemplate>                 <grid margin="2" background="{binding color}">                     <grid.columndefinitions>                         <columndefinition width="20"/>                         <columndefinition width="*" />                     </grid.columndefinitions>                     <grid.rowdefinitions>                         <rowdefinition height="auto" />                     </grid.rowdefinitions>                     <checkbox grid.row="0" grid.column="0" horizontalalignment="center" verticalalignment="center"  ischecked="{binding isvisible, mode=twoway}">                         <checkbox.style>                             <style targettype="{x:type checkbox}">                                 <setter property="cursor" value="hand"/>                                 <setter property="template">                                     <setter.value>                                         <controltemplate targettype="{x:type checkbox}">                                             <border width="15" height="15" borderbrush="gray" borderthickness="2" cornerradius="3" />                                             <controltemplate.triggers>                                                 <trigger property="ischecked" value="true">                                                     <setter property="background" value="{binding color, converter={staticresource oxycolortocolorconverter}}"/>                                                 </trigger>                                             </controltemplate.triggers>                                         </controltemplate>                                     </setter.value>                                 </setter>                             </style>                         </checkbox.style>                     </checkbox>                     <label grid.row="0" grid.column="1" content="{binding title}" padding="1" />                  </grid>             </datatemplate>         </listview.itemtemplate>     </listview> 

converter:

[valueconversion(typeof(oxycolor), typeof(brush))] class oxycolortocolor: ivalueconverter {     public object convert(object value, type targettype, object parameter, cultureinfo culture)     {         var ox = (oxycolor) value;         var color = color.fromargb(ox.a, ox.r, ox.g, ox.b);         var brush = new solidcolorbrush(color);         return brush;     }      public object convertback(object value, type targettype, object parameter, cultureinfo culture)     {         return oxycolors.purple;     } } 

you define controltemplate inside don't use background property it's never shown.

<controltemplate targettype="{x:type checkbox}">     <border width="15"              height="15"              borderbrush="gray"              borderthickness="2"              cornerradius="3"             background="{templatebinding background}"/>     <controltemplate.triggers>         <trigger property="ischecked" value="true">             <setter property="background" value="{binding color, converter={staticresource oxycolortocolorconverter}}"/>         </trigger>     </controltemplate.triggers> </controltemplate> 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -