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
Post a Comment