即使在 wpf 中设置为透明后,用户控件背景颜色也不会改变 [英] Usercontrol background color not changes even after setting to transperent in wpf

查看:43
本文介绍了即使在 wpf 中设置为透明后,用户控件背景颜色也不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了一个用作弹出窗口的用户控件,我已将用户控件背景属性设置为透明,但背景没有变得透明

Hi i have designed a usercontrol for using as an pop up and i have set the usercontrol background property as transperent but the background is not getting transperent

我需要那个浅橙色透明

这是我的用户控件的xaml代码

and here is my xaml code of user control

<UserControl
         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:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="WPFTest.UCToolTip" 
         mc:Ignorable="d" Height="231.493" Width="362.075"
         Background="Transparent"  >
<UserControl.Resources>
    <Style TargetType="{x:Type Hyperlink}">
                 <Setter Property="TextBlock.TextDecorations" Value="{x:Null}" />
    </Style>
</UserControl.Resources>
<Grid Margin="10,0,0,0">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid Background="Orange" Margin="0,0,0,33">
        <!--Your content here-->
    </Grid>
    <Polygon
    Points="0,0 15,0, 0,30" Stroke="Orange" Fill="Orange" Margin="0,198,0,1" />
</Grid>

推荐答案

问题似乎在于您错误地使用了 Grid.您需要指定项目所在的行,一旦您这样做,您就不需要所有这些边距.并且您的第一行需要有 Height="Auto" 以便它扩展以适应其中的内容.

The problem seems to be that you're using the Grid incorrectly. You need to specify which row the items are in, and once you do that, you don't need all those margins. And your first row needs to have Height="Auto" so it expands to fit the content within it.

<Grid>
    <Grid Margin="10,0,0,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0"  Background="Orange" Margin="0,0,0,0" >
            <Label>My Content</Label>
        </Grid>
        <Polygon 
            Grid.Row="1" 
            Points="0,0 15,0, 0,30" 
            Stroke="Orange" 
            Fill="Orange" 
            Margin="0,0,0,1" />
    </Grid>
</Grid>

这篇关于即使在 wpf 中设置为透明后,用户控件背景颜色也不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆