码迷,mamicode.com
首页 > Windows程序 > 详细

WPF 设置透明度和圆形图片

时间:2015-08-20 15:07:39      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:

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"/>

 

WPF 设置透明度和圆形图片

标签:

原文地址:http://www.cnblogs.com/zhaolili/p/4744920.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!