Radio button checked show image1, unchecked show image2 wpf xmal style -
i using "booleantovisibilityconverter" show 1 image when radio button checked. way can utilize same sort of style show image when radio button unchecked?
<booleantovisibilityconverter x:key="visibilityconverter" /> <radiobutton name="rbttest" ischecked="true" groupname="rbtmenugroup" style="{staticresource radiobuttonmenustyle}" > <wrappanel> <image source="/wpf1;component/images/test1.png" visibility="{binding ischecked=false ???}" style="{staticresource menuiconstyle}" /> <image source="/wpf;component/images/test2.png" visibility="{binding ischecked, converter={staticresource visibilityconverter},elementname = rbttest}" style="{staticresource menuiconstyle}" ></image> <textblock text="this testing" /> </wrappanel> </radiobutton>
i found solution time beingness before study mvvm, databinding, dependencyproperty, controltemplates.
i have added booleantovisibilityconverter class allows reverse, mean hide/collapse command when true , visible when false !
using system; using system.windows.data; using system.windows; namespace testbooleantovisibilityconverter { class booltovisibleorhidden : ivalueconverter { #region constructors /// <summary> /// default constructor /// </summary> public booltovisibleorhidden() { } #endregion #region properties public bool collapse { get; set; } public bool reverse { get; set; } #endregion #region ivalueconverter members public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { bool bvalue = (bool)value; if (bvalue != reverse) { homecoming visibility.visible; } else { if (collapse) homecoming visibility.collapsed; else homecoming visibility.hidden; } } public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture) { visibility visibility = (visibility)value; if (visibility == visibility.visible) homecoming !reverse; else homecoming reverse; } #endregion } } can reverse in xaml. <local:booltovisibleorhidden x:key="booltovisconverter" collapse="true" reverse="true" /> <local:booltovisibleorhidden x:key="booltovisconverter2" collapse="true" reverse="false" /> --------------------------------------------------------------------------------- <radiobutton name="rbttest" ischecked="true" groupname="rbtmenugroup" style="{staticresource radiobuttonmenustyle}" > <wrappanel> <--show image when radio button unchecked--> <image source="/wpf1;component/images/test1.png" visibility="{binding ischecked, converter={staticresource booltovisconverter},elementname = rbttest}" style="{staticresource menuiconstyle}" /> <--show image when radio button checked--> <image source="/wpf1;component/images/test2.png" visibility="{binding ischecked, converter={staticresource booltovisconverter2},elementname = rbttest}" style="{staticresource menuiconstyle}" ></image> <textblock text="this testing" /> </wrappanel>
reference : http://www.rhyous.com/2011/02/22/binding-visibility-to-a-bool-value-in-wpf/
wpf
No comments:
Post a Comment