c# - Winrt, changing a color, depending on a bound value -
i have gridview looks this:
<gridview itemcontainerstyle="{staticresource gridviewitemstyle2}" itemssource="{binding mymeetingssquareusers}" grid.row="1" margin="10,10,10,0" selectionmode="none" horizontalcontentalignment="left" verticalcontentalignment="bottom"> <gridview.itemspanel> <itemspaneltemplate> <itemswrapgrid orientation="vertical" maximumrowsorcolumns="1"/> </itemspaneltemplate> </gridview.itemspanel> <gridview.itemtemplate> <datatemplate> <grid height="35" width="35" margin="0,0,10,0" > <border borderbrush="red" borderthickness="1" cornerradius="15"> <ellipse> <ellipse.fill> <imagebrush stretch="fill" imagesource="ms-appx:///images/photo_empty.png"/> </ellipse.fill> </ellipse> </border> </grid> </datatemplate> </gridview.itemtemplate> </gridview>
the itemssource
use list of items of type:
public class meetinginvitee { public string id { get; set; } public string status { get; set; } public user user { get; set; } public bitmapimage photo { get; set; } }
what know is, if possible change color of border use depending on value in status
for example if had 3 possible status: accepted
, rejected
, pending
, colors set either green, red or yellow accordingly.
so if 1 of items on list had status of rejected border have red brush
conditional templates (instead of style data triggers unfortunately) way go in store app. need define 3 different templates each color , in code behind create template selector.
data template selector
public class meetingtemplateselector : datatemplateselector { public datatemplate acceptedtemplate { get; set; } public datatemplate rejectedtemplate { get; set; } public datatemplate pendingtemplate { get; set; } protected override datatemplate selecttemplatecore(object item, dependencyobject container) { datatemplate result; switch( ((meetinginvitee) item).status) { case "accepted" : result = acceptedtemplate; break; case "rejected" : result = rejectedtemplate; break; case "pending" : result = pendingtemplate; break; } return result; } }
declare templates in resources
<usercontrol.resources> <datatemplate x:key="acceptedtemplate"> <border background="green"> ... </border> </datatemplate> <datatemplate x:key="rejectedtemplate"> <border background="red"> ... </border> </datatemplate> <datatemplate x:key="pendingtemplate"> <border background="yellow"> ... </border> </datatemplate> <local:meetingtemplateselector x:key="meetingselector" acceptedtemplate="{staticresource acceptedtemplate}" rejectedtemplate="{staticresource rejectedtemplate}" pendingtemplate="{staticresource pendingtemplate}"> </local:meetingtemplateselector > </usercontrol.resources>
usage
<gridview itemcontainerstyle="{staticresource gridviewitemstyle2}" itemssource="{binding mymeetingssquareusers}" itemtemplateselector="{staticresource meetingselector}">
Comments
Post a Comment