简体   繁体   中英

Transparent background for text by opacity

I'm a little new in wpf. I want to make transparent background for the text. I achieved it with the AllowsTransparency = true; background = Colors.Transparent AllowsTransparency = true; background = Colors.Transparent but the animation was like chopping. I read here Strange Choppy WPF Animation that's common for the AllowsTransparency property, so I want to make it by opacity. I have XAML code:

 <Grid x:Name="Gridd">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Viewbox x:Name="MainWindow1">
            <TextBlock x:Name="textBlock" TextWrapping="Wrap" Text="00:00:00" FontFamily="Digital-7 Mono" FontSize="50" Grid.Row="0" Grid.Column="0"/>
        </Viewbox>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"
                    VerticalAlignment="Bottom" />
    </Grid>

I want to change opacity dynamically, each time I try to make background transparent by opacity, the text vanish also. Any tips?

I solved it with OpacityMask which "choose" color to make transparent when Opacity on the window is set to 0. Now i can choose the same Color for the OpacityMask and Background . The background vanish and text is still visible

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM