c# - Change image.Source in ListView according to boolean -


i have listview 2 columns: "visibility" , "name" of system. value of column 1: button (btn_visibility) image (img_visibility).

depending on boolean (true or false) object in code behind image should change, e.g. system.show_in_list = true; img_visibility.source = new bitmapimage(new uri(app.controller.paths.path_to_minus));

an image reachable under following relative path: app.controller.paths.path_to_"name of image", e.g. app.controller.paths.path_to_add;

my xaml-code in systemmanagementwindow.xaml:

<listview x:name="lv_systems" horizontalalignment="left" height="227" margin="313,5,0,0" verticalalignment="top" width="153" selectedindex="0" selectionchanged="listview_systems_selectionchanged">         <listview.view>             <gridview>                 <gridviewcolumn header="{x:static p:resources.systemmanagementwindow_listview_col_1}" displaymemberbinding="{binding systemname}" width="110"/>                 <gridviewcolumn header="{x:static p:resources.systemmanagementwindow_listview_col_2}"  width="34">                     <gridviewcolumn.celltemplate>                         <datatemplate>                             <button click="editvisibility" commandparameter="{binding}" width="20">                                 <image x:name="img_visibility" width="10" height="10"/>                             </button>                         </datatemplate>                     </gridviewcolumn.celltemplate>                 </gridviewcolumn>             </gridview>         </listview.view>     </listview> 

many in advance!

for searching solution:

booltoimageconverter.cs:

public class booltoimageconverter : ivalueconverter {     public object convert(object value, system.type targettype, object parameter, system.globalization.cultureinfo culture)     {         return (bool)value ? "d:\\test\\test\\bin\\debug\\img\\add.png" : "d:\\test\\test\\bin\\debug\\img\\minus.png";     }      public object convertback(object value, system.type targettype, object parameter, system.globalization.cultureinfo culture)     {         return false; // not needed     } } 

found here: https://social.msdn.microsoft.com/forums/vstudio/en-us/b0be201f-cd9a-4cde-b3f8-35014c4ca485/wpf-how-to-show-some-items-and-hide-some-items-in-a-listview-base-on-a-bool-value?forum=wpf

edited mainwindow.xaml working parallel multicolumn listview:

<window.resources>     <local:booltoimageconverter x:key="image_converter"/>     <local:booltotooltipconverter x:key="tooltip_converter"/> </window.resources> [...] <listview x:name="listview" itemssource="{binding list}">     <listview.view>         <gridview>             <gridviewcolumn header="system" displaymemberbinding="{binding name}" width="100"/>             <gridviewcolumn header="status">                 <gridviewcolumn.celltemplate>                     <datatemplate>                         <button tooltip="{binding isactive, converter={staticresource tooltip_converter}}">                             <image source="{binding isactive, converter={staticresource image_converter}}" width="15"/>                         </button>                     </datatemplate>                 </gridviewcolumn.celltemplate>             </gridviewcolumn>         </gridview>     </listview.view> </listview> 

just add following lines mainwindow.cs see result:

var list = new list<object>(); list.add(new { name = "first name", isactive = true }); list.add(new { name = "second name", isactive = true }); list.add(new { name = "third name", isactive = false }); list.add(new { name = "fourth name", isactive = true }); list.add(new { name = "fifth name", isactive = false }); list.add(new { name = "sixth name", isactive = true }); list.add(new { name = "seventh name", isactive = true }); datacontext = new { list = list }; 

hope helps.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -