xaml - Image source converter with DependencyProperty -


i'm working on wp8 mvvm app , i'm stuck @ binding problem.

i have xaml code:

<usercontrol.resources> <local:currentcategorysourceconverter x:key="currentcategorysourceconverter"/> </usercontrol.resources> 

and

<image grid.rowspan="2"        name="moviethumbnail"         stretch="fill"        width="130" height="195"        horizontalalignment="center"        verticalalignment="center">        <image.source>              <bitmapimage urisource="{binding path=image120x170,converter={staticresource currentcategorysourceconverter}}"                           createoptions="backgroundcreation"/>        </image.source> </image> 

my converter:

public class currentcategorysourceconverter : dependencyobject, ivalueconverter     {         public bool iscurrent         {             { return (bool)getvalue(currentcategoryproperty); }             set { setvalue(currentcategoryproperty, value); }         }          public static dependencyproperty currentcategoryproperty =             dependencyproperty.register("iscurrent",                                         typeof(bool),                                         typeof(currentcategorysourceconverter),                                         new propertymetadata(null));          public object convert(object value, type targettype, object parameter, cultureinfo culture)         {             if (value != null && iscurrent == true)             {                 return value;             }             else             {                 return null;             }         }          public object convertback(object value, type targettype, object parameter, cultureinfo culture)         {             throw new notimplementedexception();         }     } 

the problem can't bind iscurrent property of converter in xaml, because datacontext null when usercontrol created.

the following code results in xaml exception:

<usercontrol.resources> <local:currentcategorysourceconverter x:key="currentcategorysourceconverter"                                       iscurrent="{binding currentcategory}"/> </usercontrol.resources> 

so i'm trying set binding in code when datacontext exists:

this.model = this.datacontext categorypagecontentviewmodelapp; converter = this.resources["currentcategorysourceconverter"] currentcategorysourceconverter; binding binding = new binding(); binding.source = this.model; binding.path = new propertypath("currentcategory"); bindingoperations.setbinding(converter,currentcategorysourceconverter.currentcategoryproperty, binding); 

the problem when raise property change model on currentcategory, converter , source of image not change.

this i'm trying achieve converter: source of image should local value when category current 1 , value when category not current. i'm trying use dependency property , raising change event automatically changes when category "current" state changes. searched on internet , in undestanding should work i'm doing wrong not work. appreciated.

thanks, catalin

edit:

ok, made binding reflector, , converter parameter binding. ting it's not updating realtime.

i have pivot, , user control in each item, contains lot of images. reduce memory usage, made converter make show images current pivot item. when binded bool category set true, source of images updated unless reload page. though changes 2 properties , source , bool current categories reflected on each other.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -