I need to have two elements, one of which has a proerpty which binds to another element's property. For example:
<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</Window.Resources>
<Grid>
<TextBox x:Name="first" Text="Hello" Visibility="{Binding Text.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}, ElementName=second}" />
<TextBox x:Name="second" Background="Transparent"/>
</Grid>
The idea here is that when I start typing in the second textbox, the first textbox will disappear. This work just fine, but I receive this warning in the output window:
System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=Text.IsEmpty; DataItem=null; target element is 'TextBox' (Name='first'); target property is 'Visibility' (type 'Visibility')
Presumably this happens because the first textbox is trying to bind to a property of the second textbox, but the second textbox doesn't exist yet because it's created after the first textbox. Of course this gets resolved properly once the second textbox is created, but I would still like to eliminate the warning.
If I reverse the order of the textbox elements, the warning disappears but now my first textbox is on top of my second, so I'm unable to type in the second textbox. I've tried fixing this by setting the Z index but this doesn't work (there is no direct ZIndex property on the textbox, only Panel.ZIndex?)