[英]How to hide label until textbox information has been entered
I'm trying to have a label hidden until numbers have been entered in a texbox by the user. 我试图隐藏一个标签,直到用户在texbox中输入数字为止。 Then I want the label to show up.
然后,我要显示标签。 I'm hoping to have this all inside XAML without using C#.
我希望在不使用C#的情况下将其全部包含在XAML中。
I've tried different types of binding based on things I found online. 我根据网上发现的东西尝试了不同类型的绑定。 I think I must be close but something is still off.
我想我一定要亲近,但仍有问题。
Here's the textbox code: 这是文本框代码:
<TreeViewItem Grid.Row="1" FontSize="12" Header="Width"/>
<TextBox Text="{Binding xcoord, UpdateSourceTrigger=PropertyChanged}" Name="x" Height="20" Width="40" Grid.Row="1" Grid.Column="2" />
Here's the label code: 这是标签代码:
<Label Foreground="SteelBlue" FontWeight="Bold" HorizontalAlignment="Center" VerticalContentAlignment="Center" Height="40" Background="Transparent" x:Name="label1" FontSize="16" Width="160" Content="{Binding Text, ElementName=x}" ContentStringFormat=" {0} mm" Canvas.Left="220" Canvas.Top="382" RenderTransformOrigin="1.045,-0.141" VerticalAlignment="Top">
<Label.Style>
<Style TargetType="Label">
<Setter Property="Visibility" Value="Hidden" />
<Style.Triggers>
<DataTrigger Binding="{Binding Text.Length, ElementName=x, UpdateSourceTrigger=PropertyChanged}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
Basically anything I've tried just doesn't show the label on screen at all. 基本上,我尝试过的所有操作都根本不会在屏幕上显示标签。
Something like that might work - will hide label if texbox text is empty 这样的事情可能会起作用-如果texbox文本为空,则将隐藏标签
<TextBox x:Name "tb1"/>
<Label Foreground="SteelBlue" FontWeight="Bold" HorizontalAlignment="Center" VerticalContentAlignment="Center" Height="40" Background="Transparent" x:Name="label1" FontSize="16" Width="160" Content="{Binding Text, ElementName=x}" ContentStringFormat=" {0} mm" Canvas.Left="220" Canvas.Top="382" RenderTransformOrigin="1.045,-0.141" VerticalAlignment="Top">
<Label.Style>
<Style TargetType="Label">
<Style.Triggers>
<DataTrigger Binding="{Binding Text, ElementName=tb1}" Value="">
<Setter Property="Visibility" Value="Hidden" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.