The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
Help: Disable a Textblock RRS feed

  • Question

  • Hey Guys,

    Is there a way to make a textblock look disabled? and will be enabled after logged in to the application. What I need is to make it look like disbabled if the user is not logged in, and will look like enabled once the user logged in and will navigate to a page when the texblock is clicked. Thanks much

    Thursday, April 11, 2013 6:32 AM

Answers

  • TextBlock is supposed to be static text and should not be used for navigating to another page when tapped. Use HyperlinkButton for that since that is what it is used for generally.

    You can always do it in code behind i.e. manually restyle your control and bind its Text to something else.

    You can also check if user is logged in in the Tap handler and if he is not, simply do nothing.


    Toni Petrina
    My blog: Toni codes .NET
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful"

    Thursday, April 11, 2013 7:08 AM

All replies

  • To set textblock as not enabled, you just need to set IsEnabled property as false.

    Best Regards...

    Thursday, April 11, 2013 6:49 AM
  • TextBlock is supposed to be static text and should not be used for navigating to another page when tapped. Use HyperlinkButton for that since that is what it is used for generally.

    You can always do it in code behind i.e. manually restyle your control and bind its Text to something else.

    You can also check if user is logged in in the Tap handler and if he is not, simply do nothing.


    Toni Petrina
    My blog: Toni codes .NET
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful"

    Thursday, April 11, 2013 7:08 AM
  • Set the text color:
    using System.Windows.Media;
    
    
    textblock.Foreground = (Brush)Resources["PhoneForegroundBrush"]; // normal
    textblock.Foreground = (Brush)Resources["PhoneDisabledBrush"]; // grayed

    Thursday, April 11, 2013 8:01 AM
  • Hello Toni,

    You are correct. I just changed the textblock to button due to limited properties. I noticed that many properties especially for events are not available in textblock. Thanks again!

    By the way, I'm not allowed to do code behind :) as instructed by my boss. I need to learn the MVVM way. Kudos. Thanks again 

    Thursday, April 11, 2013 8:52 AM