question

GuoLearn-6547 avatar image
0 Votes"
GuoLearn-6547 asked GuoLearn-6547 edited

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

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-wpf
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Could you please tell me what kind of app you are developing? A WPF app, a windows forms app or a UWP app?

0 Votes 0 ·
   A  WPF app
0 Votes 0 ·

Hi,@ GuoLearn-6547. It seems difficult to set WindowsXamlHost.OpacityMask directly.You could use work around to set WindowsXamlHost to the same size as the child control, and then use the background color of the child control as the color of WindowsXamlHost to solve this problem. You can also try to refer to here.


0 Votes 0 ·
Show more comments

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered GuoLearn-6547 edited

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



· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I change the Grid background color
var brush1 = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.BlueViolet);
grid.Background = brush1;
To

 var brush1 = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Transparent);
      grid.Background = brush1;

But when I run APP the Background of Transparent not work ,the Backround show me White not the Transparent,

And what i need is Transparent not color white

0 Votes 0 ·

But which effect are you trying to do ?
II can set it transparent if I set the whole window transparent too :

127926-windowsxamlhost-transparent2.gif


0 Votes 0 ·

The effect I try to do is the WindowsXamlHost and windowsXamlHost.Child background is transparent But the whole window is not transparent
The real reason i try to do it, becouse the WindowsXamlHost and windowsXamlHost.Child can not rotate the same angle ,like this code

 <xaml:WindowsXamlHost.RenderTransform>

<TransformGroup>
<RotateTransform Angle="30"/>
</TransformGroup>
</xaml:WindowsXamlHost.RenderTransform>

  the angel=30 do not work   , so I rotate the windowsXamlHost.Child , but the WindowsXamlHost's background  had the white color so i neet it transparent.

 Is there any way can  WindowsXamlHost and windowsXamlHost.Child   rotate the same angle , If can do it, it's also helpful me a lot

0 Votes 0 ·
Show more comments