在這里,我有如下的 XAML。
<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>
現在我想添加一個控制元件,標簽“錯誤!” 在組合框“cbox”上方。

而不是使用Popup,有什么方法可以實作嗎?
uj5u.com熱心網友回復:
我認為這就是您要搜索的內容:
<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>
截屏
uj5u.com熱心網友回復:
我們可以使用畫布。
<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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/411950.html
標籤:
