Задайте вопросЗадайте вопрос
 

ОтвеченоSetting the Opacity of a xaml Control to see through it?

Ответы

  • 12 декабря 2007 г. 6:59Wei Zhou - MSFTМодераторМедали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     Отвечено

    Hi ParaDiddl

     

    I think that you can set the BackColor of ElementHost to Color.Transparent, and set opacity on hosted WPF control to achieve this. The following code shows how to do this.

     

    Code Block

    public partial class MainForm : Form

    {

        public MainForm()

        {

            InitializeComponent();

     

            this.BackColor = Color.Blue;

     

            MyWPFUserControl control = new MyWPFUserControl();

            ElementHost host = new ElementHost()

            {

                BackColor = Color.Transparent,

                Dock = DockStyle.Top,

                Height = 100,

                Child = control

            };

            this.Controls.Add(host);

        }

    }

     

    <UserControl x:Class="ForumProjects.MyWPFUserControl"

       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

       Opacity="0.5">

        <StackPanel>

            <Button>Button</Button>

            <TextBlock Height="50" Background="Red">

                This is a text.

            </TextBlock>

        </StackPanel>

    </UserControl>

     

     

    Best Regards,

    Wei Zhou

Все ответы