Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

Canvasのすべての要素を透明にする

アプリ実行


ソースコード

App.xaml
<Application x:Class="HelloWorld.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
</Application>
MainWindow.xaml
<Window x:Class="HelloWold.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="200" Width="300">
    <Canvas Width="100" Height="100" Background="Orange">
        <!-- Canvasのすべての要素に透明性が適用される -->
        <Canvas.OpacityMask>
            <LinearGradientBrush StartPoint="0, 1" EndPoint="1, 0">
                <LinearGradientBrush.GradientStops>
                    <GradientStop Offset="0" Color="#FFFF0000" />
                    <GradientStop Offset="0.33" Color="#00000000" />
                    <GradientStop Offset="0.66" Color="#FF000000" />
                    <GradientStop Offset="0.9" Color="#22000000" />
                </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
        </Canvas.OpacityMask>
        <Rectangle Canvas.Top="0" Canvas.Left="0" Width="50" Height="50" Fill="Red" />
        <Rectangle Canvas.Top="50" Canvas.Left="50" Width="50" Height="50" Fill="Blue" />
        <Button Canvas.Top="60" Canvas.Left="25">こんにちは</Button>
    </Canvas>
</Window>