【问题标题】:Textblock not showing文本块不显示
【发布时间】:2019-02-13 05:31:37
【问题描述】:

我的应用程序 WPF 中有一个 UserControl,但当一切正常时,我使用它的文本块“tBlockLunarDay”不显示。我试图修复,但我不能。你能帮我解决一下吗?

我的用户控件

<UserControl x:Class="CalendarPlus.ControlCalendar"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:CalendarPlus"
             mc:Ignorable="d" 
             d:DesignHeight="60" d:DesignWidth="60" Loaded="ControlCalendar_OnLoaded">
    <Grid>
        <Border x:Name="border" BorderThickness="1" BorderBrush="Red" CornerRadius="7">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1.5*"></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="1.5*"></RowDefinition>
                    <RowDefinition></RowDefinition>
                </Grid.RowDefinitions>

                <Canvas>
                    <TextBlock x:Name="tBlockDay" FontFamily="Times New Roman" FontWeight="Bold" TextAlignment="Center" FontSize="30" Width="30" Height="30" Padding="0" Canvas.Left="5" Canvas.Top="3" Foreground="AliceBlue">5</TextBlock>
                </Canvas>

                <Canvas Grid.Row="1" Grid.Column="1" ZIndex="99" Visibility="Visible" IsEnabled="True">
                    <TextBlock x:Name="tBlockLunarDay" Foreground="AntiqueWhite" FontFamily="Times New Roman" FontSize="12" TextAlignment="Center" FontWeight="Bold" FontStyle="Italic" Width="20" Height="20" Canvas.Top="2" Canvas.Left="1" Visibility="Visible" IsEnabled="True">19</TextBlock>
                </Canvas>

                <Canvas Grid.Column="1">
                    <Image x:Name="imgStar" Width="15" Height="15" Canvas.Top="3" Canvas.Right="3" Source="pack://siteoforigin:,,,/Resources/Star512.png"></Image>
                </Canvas>

            </Grid>
        </Border>
    </Grid>
</UserControl>

我不能上传大部分代码,所以请对这种不便表示同情。这是 .CS 文件中的代码 https://drive.google.com/open?id=1GI-3BIYsqh5IFFTIMY3ubFFxscQT4Ei6

【问题讨论】:

  • 你确定它是隐形的吗?它很可能在那里,但由于前景色“AntiqueWhite”,能见度不是很好。尝试使用不同的颜色。顺便说一句,你为什么需要那些画布?
  • 请注意,将每个元素包装在 Canvas 中是没有意义的。如果你想抵消他们的位置,只需设置他们的 Margin 属性。

标签: c# wpf wpf-controls


【解决方案1】:

我刚试过,你只需要改变文字的颜色,我也看不到“AntiqueWhite”文字。

也不确定这是否是故意的,但如果你使用画布来布局文本框,你可以像下面这样在文本框标签内设置它们的位置。

<TextBlock Grid.Row="1" Grid.Column="1" x:Name="tBlockLunarDay" Foreground="Black" FontFamily="Times New Roman" FontSize="12" TextAlignment="Center" FontWeight="Bold" FontStyle="Italic" Width="20" Height="20" Canvas.Top="2" Canvas.Left="1" Visibility="Visible" IsEnabled="True">19</TextBlock>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多