Usercontrol background color not changes even after setting to transperent in wpf

余生长醉 提交于 2020-01-06 21:46:39

问题


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

I need that light orange to be transparent

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>


回答1:


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>


来源:https://stackoverflow.com/questions/36771493/usercontrol-background-color-not-changes-even-after-setting-to-transperent-in-wp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!