Monday, 15 July 2013

windows phone 8 - Change color StackPanel, according to the data received from the Binding, in XAML -



windows phone 8 - Change color StackPanel, according to the data received from the Binding, in XAML -

i want alter color of stackpanel, according info (1, 2, 3...) received binding (value), should use?

<stackpanel grid.column="1"> <border height="50" width="auto" margin="3" background="black"> <textblock fontsize="18" fontweight="bold" textwrapping="wrap" foreground="white" text="{binding valor}" verticalalignment="center" horizontalalignment="center"/> </border> </stackpanel>

use converter: http://www.smallandmighty.net/blog/using-value-converters-to-change-the-visibility-of-a-control

<window.resources> <converters:colorconverter x:key="colorconverter"/> </window.resources>

xaml:

<stackpanel background="{binding valor, converter={staticresource colorconverter}}"/>

your converter this:

public class colorconverter: ivalueconverter { public object convert(object value, type targettype, object parameter,cultureinfo culture) { if (value != null) { int value = (int)value; if(value == 1) homecoming colors.green; else if(value == 2) homecoming colors.red; [...] } homecoming null; } public object convertback(object value, type targettype, object parameter, cultureinfo culture) { throw new notimplementedexception(); }

xaml windows-phone-8

No comments:

Post a Comment