Forums

Opacity binding
Last Post 10 Feb 2016 02:06 PM by jesevis. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
jesevisUser is Offline
New Member
New Member
Posts:24


--
10 Feb 2016 11:01 AM
    I'm trying to make a fade effect for a TextBlock control.

    I have this:


    private TextBlock _exitMessage;
    public TextBlock ExitMessage
    {
    get
    {
    if (_exitMessage == null)
    {
    _exitMessage = new TextBlock();

    }
    return _exitMessage;
    }
    set { SetProperty(ref _exitMessage, value); } }


    I bind its Opacity to a XAML control like this:

      <TextBlock FontSize=30  Text={Binding ExitMessage.Text} Opacity={Binding ExitMessage.Opacity} Visibility={Binding ExitMessage.Visibility} /> 
    


    And on Update I want to decrement opacity let's say every second. ( ExitMessage.Opacity -= 0.1f )

    Unfortunately, Opacity value changes, but Text doesn't disappear.

    Any idea what may be wrong or how could I do this better?

    I know that I could do this with an additional value and it would work, but I kinda don't want such properties layin around.

     <TextBlock Opacity={Binding TextBlockOpacity}/>
    


    and

     private float _textBlockOpacity; 
     public float TextBlockOpacity{ get { return _textBlockOpacity; } set { SetProperty(ref _textBlockOpacity, value); } } 
    
    Filip DušekUser is Offline
    Advanced Member
    Advanced Member
    Posts:676


    --
    10 Feb 2016 02:04 PM
    Using TextBlock class instead just simple Opacity property is just wrong. Properties are not "just laying" around, that's exactly what they are for. You could use animations too, UI does support them.
    jesevisUser is Offline
    New Member
    New Member
    Posts:24


    --
    10 Feb 2016 02:06 PM
    Thanks for the suggestion. I'll try animations then.
    You are not authorized to post a reply.