Microsoft.Toolkit.Wpf.UI.XamlHost.WindowsXamlHost.OpacityMask can not work

GuoLearn 251 Reputation points
2021-08-31T01:50:51.02+00:00

when set the WindowsXamlHost.OpacityMask =ImageBrush it not Effective ,the WindowsXamlHost background color is white any way.
how can i make the WindowsXamlHost background color is Transparent

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,694 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 82,321 Reputation points
    2021-08-31T10:23:24.683+00:00

    You can change the background color of the container control
    With a Grid :

    Windows.UI.Xaml.Controls.Grid grid = null;  
      
    private void WindowsXamlHost_ChildChanged(object sender, EventArgs e)  
    {  
        WindowsXamlHost windowsXamlHost = (WindowsXamlHost)sender;  
        grid = (Windows.UI.Xaml.Controls.Grid)windowsXamlHost.Child;  
        if (grid != null)  
        {  
            var brush1 = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.BlueViolet);  
            grid.Background = brush1;  
            Windows.UI.Xaml.Controls.InkCanvas MyControl2 = new Windows.UI.Xaml.Controls.InkCanvas();  
            MyControl2.Name = "InkCanvas1";  
            MyControl2.InkPresenter.InputDeviceTypes =  Windows.UI.Core.CoreInputDeviceTypes.Mouse |  
                Windows.UI.Core.CoreInputDeviceTypes.Pen |  Windows.UI.Core.CoreInputDeviceTypes.Touch;  
            grid.Children.Add(MyControl2);  
        }  
    }  
    

    in XAML :

          <XamlHost:WindowsXamlHost HorizontalAlignment="Left" Height="183" Margin="46,64,0,0" VerticalAlignment="Top" Width="426" InitialTypeName="Windows.UI.Xaml.Controls.Grid" ChildChanged="WindowsXamlHost_ChildChanged" Grid.ColumnSpan="2"/>  
    

    127921-windowsxamlhost-color.gif