Saturday 15 May 2010

c# - Resolve XAML Binding through Code on Windows Phone 8 -


I have a converter that provides default value for empty strings. Obviously you can not add a binding to the ConverterParameter so I add a property in the converter, which I instead obliged to do.

However, the price is returning to normal property for a series of "System.Windows.Data.Binding" instead of my price.

I am binding in this code so I can return the actual local string I want, how do I fix it?

Here is my converter class (depending on the answer):

  public class DefaultForNullOhWhiteSpaceStringConverter: {{public command default {set; get; } Public Object Convert (Object Value, Type TargetType, Object Parameter, System.Globalization.CultureInfo Culture) {If (string.IsNullOhWhiteSpace ((String) value)!) {Return Value; } Else {if (parameter! = Null) {return parameter; } And   

and my XML:

  & lt; Phone: PhoneApplicationPage.Resources & gt; & Lt; TC: DefaultForNullOrWhiteSpaceStringConverter X: main = "WaypointNameConverter" default = "{binding path = LocalizedResources.Waypoint_NoName, mode = - bar, source = {StaticResource LocalizedStrings}}" /> & Lt; / Phone: PhoneApplicationPage.Resources & gt; & Lt; TextBlock Text = "{binding name, converter = {static resource WaypointNameConverter}}" />   

Any ideas?

"itemprop =" text ">

You should be able to accomplish this that your default Inheriting and changing from property.

  public class DefaultForNullOhWhiteSpaceStringConverter: dependency object, IValueConverter {public string DefaultValue {get {return (string) GetValue (DefaultValueProperty); } Set {Set Value (DefaultVolProperty, Value); }} // Use a dependency property as the backing store for DefaultValue. This enables animation, style, binding, etc ... public static Read Only DependencyProperty DefaultValueProperty = DependencyProperty.Register ("DefaultValue", typeof (string), typeof (DefaultForNullOrWhiteSpaceStringConverter), New PropertyMetadata (zero)); ... ...    

No comments:

Post a Comment