wpf - Conditional display of image in c# -


i trying conditionaly display image. read quite bit valueconverters , triggers, believe there has easier solution easy problem.

the xaml:

 <image source="c:\users\niko\pictures\red.png" isenabled="{binding ison}"></image> 

the code behind:

namespace mvvm { public class globals {     int = 2;      public bool ison     {                 {             if (i == 1 )                 return true;             else                 return false;         }      } } 

i played around integer i see if image gets displayed or not. advice apreciated!

bind image's visibility ison , use built in booleantovisibilityconverter.

<image source="c:\users\niko\pictures\red.png" visibility="{binding visibility, converter={staticresource booltovis}}"/> 

then add booleantovisibilityconverter static resource in either <window.resources> window or <application.resources> whole application.

<booleantovisibilityconverter x:key="booltovis"/> 

note x:key name use reference converter after staticresource.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -