Please look 5 min at this simple bug :
<textblock (...) Width="0" />
Working great, the textBox appears to be 0px thin. Works with value like, 2, 3, 4…
Now that is NOT working :
<TextBlock (...) />
<TextBlock.Width>
<MultiBinding Converter="{StaticResource WidthConverter}">
<MultiBinding.Bindings>
<Binding RelativeSource="{RelativeSource Self}" />
<Binding RelativeSource="{x:Static RelativeSource.Self}" Path="TemplatedParent.Parent.ActualWidth" />
</MultiBinding.Bindings>
</MultiBinding>
<TextBlock.Width>
</TextBlock>
Public Class WidthConverter
Implements IMultiValueConverter
Public Function Convert(ByVal values() As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IMultiValueConverter.Convert
Return 0
End function
end class
why can i set zero value to TextBox.Width in xaml and not in code behind ?
By using a converter, when returing 0, the TextBlock.Width is not set to 0 but to “auto”, i can read the text
The property is of type
double, you return anint, change it toreturn 0.0and it should work.(The reason being that bindings set properties via reflection, and there is no implicit conversion in that, so if you return an
intthat is considered to be not a number anddouble.NaNis the value used to describe theAutobehavior)