【发布时间】:2022-01-24 01:14:16
【问题描述】:
我正在尝试访问边界内的 TextBlock“fastcolor”。
边框位于名为 fastcard 的 DockPanel 中,我将其作为参数传递给另一个类。
我的问题是:如何访问边界内名为“fastcolor”的TextBlock?
这段代码:
(TextBlock)fastcard.Children[0]
允许访问边框,而这段代码:
(TextBlock)fastcard.Children[1]
允许访问名为“fastprice”的 TextBlock
XAML:
<DockPanel Canvas.ZIndex="1" x:Name="fastcard" Background="White" Width="225" Height="300" Visibility="Hidden">
<Border BorderBrush="Black" BorderThickness="1">
<TextBlock x:Name="fastcolor" FontSize="10" Foreground="Black" Width="225" Height="50" VerticalAlignment="Top" Visibility="Visible" />
</Border>
<TextBlock x:Name="fastprice" Text="Price: " FontSize="15" Foreground="Black" Width="150" Height="25" VerticalAlignment="Top" Margin="-290,50,0,0" FontWeight="Bold"/>
</DockPanel>
【问题讨论】:
标签: c# wpf xaml children textblock