图像不透明度级别为 100%

发布于 2024-12-15 05:40:40 字数 268 浏览 2 评论 0原文

我有一个用作按钮的图像,但在鼠标输入时我希望不透明度为 100%,而此时仅为 80%。我该怎么做呢?

这是我的鼠标输入事件

private void playButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            double x;


        }

我正在使用混合,silverlight 4 谢谢

I have an image that I am using as a button but on the mouse enter I want the opacity to be 100%, which at this point is only 80%. How would I do that?

here is my mouse enter event

private void playButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            double x;


        }

I am using blend, silverlight 4
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哥,最终变帅啦 2024-12-22 05:40:40

假设您的事件被“击中”...

private void playButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
   if ( sender is Button )
      ((Button)sender).Opacity = 1;
}

也就是说,您还应该响应鼠标移出事件并将不透明度设置回 0.8

您也可以使用视觉状态管理器来执行此操作。 这是 MSDN 上的一个很好的示例

assuming your event is being "hit"...

private void playButton_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
   if ( sender is Button )
      ((Button)sender).Opacity = 1;
}

that said, you should also respond to the mouse out event and set the opacity back to .8

you could use the visual state manager to do this as well. here is a nice example on MSDN

醉生梦死 2024-12-22 05:40:40

您还可以在 XAML 中完成这一切。这需要 Blend SDK for Silverlight 4 (它实际上不需要 Blend,所以如果您没有或使用 Expression Blend,请不要被误导)。假设您从以下内容开始:

<UserControl x:Class="SilverlightApplication2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>
        <Image Source="Penguins.jpg" Opacity="0.8"/>
    </Grid>
</UserControl>

您可以将其转换为如下内容:

<UserControl x:Class="SilverlightApplication2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
    mc:Ignorable="d">

    <Grid>
        <Image Source="Penguins.jpg" Opacity="0.8">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseEnter">
                    <ei:ChangePropertyAction PropertyName="Opacity" Value="1.0"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseLeave">
                    <ei:ChangePropertyAction PropertyName="Opacity" Value="0.8"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Image>
    </Grid>
</UserControl>

You could also do it all in XAML. This requires the Blend SDK for Silverlight 4 (which actually does not require Blend, so don't be misled if you don't have or use Expression Blend). Assuming you started with something like:

<UserControl x:Class="SilverlightApplication2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>
        <Image Source="Penguins.jpg" Opacity="0.8"/>
    </Grid>
</UserControl>

You could transform it into something like this:

<UserControl x:Class="SilverlightApplication2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
    mc:Ignorable="d">

    <Grid>
        <Image Source="Penguins.jpg" Opacity="0.8">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseEnter">
                    <ei:ChangePropertyAction PropertyName="Opacity" Value="1.0"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="MouseLeave">
                    <ei:ChangePropertyAction PropertyName="Opacity" Value="0.8"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Image>
    </Grid>
</UserControl>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文