Here I have the XAML as follows.
<StackPanel>
<Label Content="a label here" Height="30" Background="LightBlue"/>
<Grid Background="LightCoral">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Label Content="first col"/>
<ComboBox Grid.Column="1" x:Name="cbox"/>
<Button Content="showerror" Grid.Column="2" HorizontalAlignment="Center"/>
</Grid>
</StackPanel>
Now I want to add a control, the label "error!" above the Combobox "cbox".
Rather than using Popup, is there any way to achieve it?
CodePudding user response:
I think this is what you searching for:
<Grid>
<StackPanel>
<Label Content="a label here" Height="30" Background="LightBlue"/>
<Grid Background="LightCoral">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="1" Grid.Row="0" Content="Error"/>
<Label Grid.Column="0" Grid.Row="1" Content="first col"/>
<ComboBox Grid.Column="1" Grid.Row="1"/>
<Button Content="showerror" Grid.Column="2" Grid.Row="1" HorizontalAlignment="Center"/>
</Grid>
</StackPanel>
</Grid>
CodePudding user response:
We can use Canvas.
<Canvas>
<TextBlock Background="WhiteSmoke" Foreground="Red" Text="error" Canvas.Left="110" Canvas.Top="20"/>
<Canvas.Style>
<Style TargetType="{x:Type Canvas}">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsShown}" Value="True">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Canvas.Style>
</Canvas>

