怎么用WPF做半透明渐变颜色的按扭

a6965921z 2010-02-07 10:16:50
怎么用WPF做半透明渐变颜色的按扭
...全文
1347 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuzhoufeng888 2011-03-31
  • 打赏
  • 举报
回复
貌似我没运行出预期效果来!
lzlmis2010 2010-08-30
  • 打赏
  • 举报
回复
学习一下。
a6965921z 2010-02-09
  • 打赏
  • 举报
回复
知道了 原来在外面在套个GRID
a6965921z 2010-02-09
  • 打赏
  • 举报
回复
引用 5 楼 goldfire_001 的回复:
你的ContentPresenter呢。。最重要的东西都丢了。你的Content往哪显示啊?

ContentPresenter写到哪里 没地方写了
a6965921z 2010-02-09
  • 打赏
  • 举报
回复
我晕死 你这个要写在前台 不能写在后台的 我写的WPF应用程序 不是SL
jackson35296 2010-02-09
  • 打赏
  • 举报
回复
少写了点东西

<Button Width="200" Height="100">
<Button.Background>
<LinearGradientBrush StartPoint="0,1" EndPoint="1,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#80FF0000" Offset="0.0" />
<GradientStop Color="#8000FF00" Offset="0.5" />
<GradientStop Color="#800000FF" Offset="1.0" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Button.Background>
</Button>
jackson35296 2010-02-09
  • 打赏
  • 举报
回复

<Button Width="200" Height="100">
<Button.Background>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<GradientStop Color="#80FF0000" Offset="0.0" />
<GradientStop Color="#8000FF00" Offset="0.5" />
<GradientStop Color="#800000FF" Offset="1.0" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Button.Background>
</Button>
a6965921z 2010-02-09
  • 打赏
  • 举报
回复
我不用template 会显示渐变界面 用了 template 没渐变 变空白了
a6965921z 2010-02-09
  • 打赏
  • 举报
回复
Window x:Class="WpfApplication16.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="简便效果" Height="186" Width="339">
<Grid x:Name="GelShine">
<Grid Margin="0,0,0,119">

</Grid>
<Grid Margin="0,30,0,33">
<Label Margin="18,0,264,55" Name="label1" Height="24" VerticalAlignment="Bottom">帐号</Label>
<Label Margin="18,0,0,35" Name="label2" Height="23" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="33">密码</Label>
<TextBox Margin="57,0,0,59" Name="textBox1" HorizontalAlignment="Left" Width="101" Height="19" VerticalAlignment="Bottom" />
<TextBox Margin="57,0,0,33" Name="textBox2" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="101" />
</Grid>
<Grid Height="35" VerticalAlignment="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="158*" />
<ColumnDefinition Width="159*" />
</Grid.ColumnDefinitions>
<Button Grid.Column="1" Margin="72,0,27,15" Name="button1" Click="button1_Click" Content="登陆"></Button>
</Grid>
</Grid>

</Window>
我的前台
a6965921z 2010-02-09
  • 打赏
  • 举报
回复
content不是写在前台么
jv9 2010-02-09
  • 打赏
  • 举报
回复
引用 4 楼 a6965921z 的回复:
我用了ControlTemplate  效果是出来 但是字体被遮住了
<Application.Resources>

        <LinearGradientBrush x:Key="GrayBlueGradientBrush"    StartPoint="0,0" EndPoint="1,1">
            <GradientStop Color="Blue"  Offset="0" />
            <GradientStop Color="#CCCCFF" Offset="0.5" />
            <GradientStop Color="DarkGray" Offset="1" />
        </LinearGradientBrush>

        <Style TargetType="Button">
            <Setter Property="Background"      Value="{StaticResource GrayBlueGradientBrush}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">

                        <Rectangle x:Name="GelBackground"
                Opacity="1" RadiusX="9"
                RadiusY="9"
                Fill="{TemplateBinding Background}"
                                  > </Rectangle>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>


            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Foreground" Value="Red" />
                </Trigger>
            </Style.Triggers>


        </Style>

    </Application.Resources>
</Application>


你的代码缺少Content属性。看看这里的代码:

http://silverlightchina.net/html/works/2009/1127/266.html

http://silverlightchina.net/html/tips/2010/0104/556.html
Goldfire_001 2010-02-08
  • 打赏
  • 举报
回复
你的ContentPresenter呢。。最重要的东西都丢了。你的Content往哪显示啊?
bigzoom 2010-02-08
  • 打赏
  • 举报
回复
使用expression blend可以很轻松的制作车半透明的渐变按钮,如果没有使用过expression blend,那么建议你去看看这本书,《Foundation Expression Blend 3 with Silverlight》,里面有如何制作该效果按钮的很详细的说明!!!你也可以在CSDN下载频道下载该电子书。注:该书为英文版,不过比较通俗易懂。
xingjunli 2010-02-08
  • 打赏
  • 举报
回复
做用户控件,自定义Button Context
Goldfire_001 2010-02-08
  • 打赏
  • 举报
回复
俄,这个貌似网上非常多吧。

给你一个官方滴。

http://msdn.microsoft.com/zh-cn/library/bb613593.aspx
a6965921z 2010-02-08
  • 打赏
  • 举报
回复
我用了ControlTemplate 效果是出来 但是字体被遮住了
<Application.Resources>

<LinearGradientBrush x:Key="GrayBlueGradientBrush" StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="Blue" Offset="0" />
<GradientStop Color="#CCCCFF" Offset="0.5" />
<GradientStop Color="DarkGray" Offset="1" />
</LinearGradientBrush>

<Style TargetType="Button">
<Setter Property="Background" Value="{StaticResource GrayBlueGradientBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">

<Rectangle x:Name="GelBackground"
Opacity="1" RadiusX="9"
RadiusY="9"
Fill="{TemplateBinding Background}"
></Rectangle>
</ControlTemplate>
</Setter.Value>
</Setter>



<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Red" />
</Trigger>
</Style.Triggers>


</Style>

</Application.Resources>
</Application>

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧