locked
Help with a Dependency Property RRS feed

  • Question

  • Hello again,

    I've implimented a new dependency property of type Double for the opacity of a certain item. It's great apart from the fact that I want it to look like the Opacity control that's already in Blend. You know, with the bar and the 100% and stuff. Any ideas how I can do this please?
    Wednesday, August 6, 2008 5:30 PM

Answers

  • Hi Mark,

    Find below the code written by myself, which exactly does what you want..

    ----------------------------------------------------------------------------------------------------------------------------------------
    XAML CODE
    ----------------------------------------------------------------------------------------------------------------------------------------

    <Window
    xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
    x:Class="OpacityController.Window1"
    x:Name="Window"
    Title="Window1"

    Width="640" Height="480" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
    <
    Window.Resources>

    <Storyboard x:Key="Opacity_Animation">
    <
    DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="circle" Storyboard.TargetProperty="(UIElement.Opacity)">
    <
    SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
    <
    SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
    </
    DoubleAnimationUsingKeyFrames>
    </
    Storyboard>
    </
    Window.Resources>

    <Grid x:Name="LayoutRoot">
    <
    Ellipse Fill="#FFA32E2E" Stroke="{x:Null}" Margin="239,79,293,0" x:Name="circle" VerticalAlignment="Top" Height="100"/>
    <
    Slider Margin="189,0,251,144" VerticalAlignment="Bottom" d:LayoutOverrides="Height" ValueChanged="OnValueChanged" x:Name="slider"/>
    </
    Grid>
    </
    Window>

    ------------------------------------------------------------------------------------------------------

    ------------------------------------------------------------------------------------------------------
    Code Behind
    ------------------------------------------------------------------------------------------------------

    private void OnValueChanged(object sender, RoutedEventArgs e)
    {

    int i=this.Resources.Count;
    Object obj=new object();
    obj = this.Resources[
    "Opacity_Animation"] ;
    Storyboard mySB = new Storyboard();
    mySB = (
    Storyboard)obj;

    mySB.Begin(this, HandoffBehavior.SnapshotAndReplace, true);
    mySB.Pause(this);
    mySB.Seek(this,
    TimeSpan.FromMilliseconds(slider.Value * 100), TimeSeekOrigin.BeginTime);
    }

    ------------------------------------------------------------------------------------------------------

    -BALA

     

    Sunday, August 31, 2008 6:32 AM