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
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
Could you please tell me what kind of app you are developing? A WPF app, a windows forms app or a UWP app?
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.
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"/>

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
But which effect are you trying to do ?
II can set it transparent if I set the whole window transparent too :

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
6 people are following this question.