c# - XAML Binding multiple sources -
ok, have set of textblock's.
<grid x:name="mygrid"> <textblock text={binding value1} /> <textblock text={binding value2} /> </grid> and c# backend:
mydata.value1 = "value1"; mydata.value2 = "value2"; mygrid.datacontext = mydata; now, want bind blocks foreground color this:
//c# private bool isviewingpage1; private bool isviewingpage1 { { return this.isviewingpage1; } set { this.isviewingpage1 = value; notifypropertychanged(); } } //xaml <grid x:name="mygrid"> <textblock text={binding value1} foreground={binding isviewingpage1, converter={staticresource myconverter}} /> <textblock text={binding value2} foreground={binding isviewingpage1, converter={staticresource myconverter}} /> </grid> so, in case if isviewingpage1 == true, first textblock green , second red. if false, first red , second - green. converters working good. how can bind 2 different values 1 element?
i tried this:
public class myclass : inotifypropertychanged { public mydatatype mydata; public bool isviewingpage1; //inotifypropertychanged implemetation } //... myclass = new myclass(); a.mydata = mydata; a.isviewingpage1 = isviewingpage1; mygrid.datacontext = a; //xaml <grid x:name="mygrid"> <textblock text={binding mydata.value1} foreground={binding isviewingpage1, converter={staticresource myconverter}} /> <textblock text={binding mydata.value2} foreground={binding isviewingpage1, converter={staticresource myconverter}} /> </grid> ...but did not me. ideas?
the logic determine colour, or @ least status (colour should view specific not defined in model) of text blocks should in view model. can have status each text block , bind them, in view model can set statuses of text blocks based on isviewingpage bool.
Comments
Post a Comment