【问题标题】:Usercontrol background color not changes even after setting to transperent in wpf即使在 wpf 中设置为透明后,用户控件背景颜色也不会改变
【发布时间】:2016-04-21 13:42:51
【问题描述】:

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

我需要那个浅橙色是透明的

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

<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>

【问题讨论】:

  • 背景颜色未在您包含在答案中的 XAML 中设置,它是由视觉树上方的另一个元素设置的
  • 是的,它的用户控件大小,它不能进一步减小。如果将用户控件边框减小到网格大小,那么多边形将不可见,多边形以外的区域是该颜色:(
  • 您需要从父控件中删除Background="AntiqueWhite"
  • 我没有在任何地方设置它 ..??你从哪里询问删除?
  • 在您的项目中搜索“AntiqueWhite”

标签: c# wpf xaml user-controls


【解决方案1】:

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

<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>

【讨论】:

  • 他想让外面的区域透明,而不是改变橙色区域的不透明度
  • @GlenThomas 好点,我没有看多边形中的点。
  • 这不能回答问题。问题是如何使控件透明
  • @GlenThomas 将他的代码复制并粘贴到测试项目中。试试吧。然后试试我的版本。
  • 所以他的XAML没有提供透明背景的控件(不包括橙色区域)?
猜你喜欢
  • 2011-06-26
  • 2011-04-14
  • 2020-03-03
  • 2011-02-11
  • 2015-07-10
  • 2019-09-29
  • 2021-10-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多