1

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

2 Answers 2

2

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

2

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.