Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set transparent for user control in wpf

Tags:

wpf

I create a message box user control, radius for corner as below image, however, I cannot set transaparent for this user control. Please help me.

Thanks so much.

enter image description here

Update:

I've implemented as your instruction, but it isn't still transparent, I think that background's user control is white color, please help me. The below is my code:

<UserControl x:Class="Nanote.TestDialog"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             d:DesignHeight="200"
             Height="200" Width="450"
             d:DesignWidth="300"
             mc:Ignorable="d">
    <Border CornerRadius="20" BorderBrush="Black" BorderThickness="10" 
        Background="Transparent">
        <Rectangle Fill="White" Margin="10" />
    </Border>
</UserControl>
like image 982
PeaceInMind Avatar asked Jan 10 '23 23:01

PeaceInMind


2 Answers

Consider the following XAML:

<Grid Background="Red">
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid Margin="20">
        <Border CornerRadius="20" BorderBrush="Black" BorderThickness="10" 
            Background="Transparent">
            <Rectangle Fill="White" />
        </Border>
    </Grid>
    <Grid Grid.Row="1" Margin="20">
        <Rectangle Fill="White" />
        <Border CornerRadius="20" BorderBrush="Black" BorderThickness="10" 
            Background="Transparent" />
    </Grid>
    <Border Grid.Row="2" CornerRadius="20" BorderBrush="Black" BorderThickness="10" 
        Background="White" Margin="20">
        <Rectangle Fill="White" Margin="10" />
    </Border>
</Grid>

This produces the following output:

enter image description here

Hopefully you can now work out your own solution from this example.

like image 123
Sheridan Avatar answered Apr 06 '23 01:04

Sheridan


First set the background of your control to transparent then add border with radius(CornerRadius="10") , INSIDE that border you put the content GRID

 <Border BorderBrush="Black"  BorderThickness="1,1,1,1" Background="White" CornerRadius="10,10,10,10">
 <Grid ></Grid>
 </Border>
like image 43
Dimitrije Zoroski Avatar answered Apr 06 '23 01:04

Dimitrije Zoroski