tags:

views:

58

answers:

1

I have a bound textbox and I need to change its associated display label to bold upon the presence of any content. I dont want to use javascript if at all possible.

Thanks

+2  A: 

Why would javascript be involved?

Anyway, if this is really wpf, bind the FontWeight property of your label to the textbox's text property, using custom converter that converts null/empty strings to Normal font weight, and non-null/non-empty to Bold.

John Gardner
I had been searching and seen a similar issue which was solved with js ;)
RobDog888
Thanks, sounds like this will work but the textbox is already bound to a custom converter. Can I use more then one and if so how? Thanks
RobDog888
I'd like to see that link, where a WPF issue is solved with JS....
Wonko the Sane
this wouldn't be a converter on the textbox, it would be a converter on the label. something like <Label FontWeight="{Binding ElementName=TextBox,Path=Text,Converter={StaticResource ConvertNonEmptyTextToBoldConverter}}"/> or something like that.
John Gardner
Thank You John. This is what I ended up using...//Label control:FontWeight="{Binding Path=TextNumber, Converter={StaticResource fontWeightConverter}}"And the converter...
RobDog888
class FontWeightConverter : IValueConverter{ public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var sourceValue = (string)value; if (!string.IsNullOrEmpty(sourceValue)) { return System.Windows.FontWeights.Bold; } else return System.Windows.FontWeights.Normal; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException("ConvertBack is not supported"); }}
RobDog888