WPF 設置透明度和圓形圖片


1 設置效果為

2 窗體中代碼為

<Window x:Class="QyNodeTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Style/Style.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Grid Style="{StaticResource bc}">
        <Border  Background="{StaticResource OpacityBrush}" Margin="0 180 0 0" VerticalAlignment="Center" Padding="10">
            <Image Source="/Img/19.jpg" Width="46" Height="46"   Clip="{StaticResource ResourceKey=clipGeometry}"></Image>
        </Border>   
    </Grid>
</Window>

3 樣式文件style.xaml中代碼為

  <Style TargetType="Grid" x:Key="bc">
        <Setter Property="Background">
            <Setter.Value>
                <ImageBrush ImageSource="/Img/loginBg.png"/>
            </Setter.Value>
        </Setter>
    </Style>
  
    <GeometryGroup x:Key="clipGeometry" FillRule="Nonzero">
        <EllipseGeometry RadiusX="23" RadiusY="23" Center="23, 23"></EllipseGeometry>
    </GeometryGroup>
    <SolidColorBrush Color="#2c2f3e" Opacity="0.8" x:Key="OpacityBrush"/>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM