Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. setting visibility of label in wpf

setting visibility of label in wpf

Scheduled Pinned Locked Moved WPF
wpfcsharpdatabasewcfhelp
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sumit7034
    wrote on last edited by
    #1

    hi I am binding label through <Label Content="{Binding Path=OrderDetails.OrderPaymentId}" FontSize="20"> now i want if the value of OrderDetails.OrderPaymentId=0 then the visibility of label become collapsed please help how to do this using style or trigger

    R K 2 Replies Last reply
    0
    • S sumit7034

      hi I am binding label through <Label Content="{Binding Path=OrderDetails.OrderPaymentId}" FontSize="20"> now i want if the value of OrderDetails.OrderPaymentId=0 then the visibility of label become collapsed please help how to do this using style or trigger

      R Offline
      R Offline
      realJSOP
      wrote on last edited by
      #2

      You need to create a value converter class, and bind the Visibility property to it in your xaml.

      .45 ACP - because shooting twice is just silly
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

      S 1 Reply Last reply
      0
      • R realJSOP

        You need to create a value converter class, and bind the Visibility property to it in your xaml.

        .45 ACP - because shooting twice is just silly
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

        S Offline
        S Offline
        sumit7034
        wrote on last edited by
        #3

        <Label.Style> <Style> <Style.Triggers> <DataTrigger Binding="{Binding Path=OrdeDetails.OrderPaymentId}" Value="0"> <Setter Property="Label.Visibility" Value="Collapsed"></Setter> </DataTrigger> </Style.Triggers> </Style> </Label.Style>

        I 1 Reply Last reply
        0
        • S sumit7034

          <Label.Style> <Style> <Style.Triggers> <DataTrigger Binding="{Binding Path=OrdeDetails.OrderPaymentId}" Value="0"> <Setter Property="Label.Visibility" Value="Collapsed"></Setter> </DataTrigger> </Style.Triggers> </Style> </Label.Style>

          I Offline
          I Offline
          Ian Shlasko
          wrote on last edited by
          #4

          Or, like John said, write a value converter... 1) Create a class that inherits from IValueConverter 2) Implement the Convert function such that it returns Visibility.Collapsed for 0, or Visibility.Visible for anything else. 3) Create an instance of that class in your resources section in the XAML, and give it a key 4) Reference it in the binding: {Binding OrderDetails.OrderPaymentId,Converter={StaticResource MyConverter}}

          Proud to have finally moved to the A-Ark. Which one are you in?
          Author of the Guardians Saga (Sci-Fi/Fantasy novels)

          D 1 Reply Last reply
          0
          • S sumit7034

            hi I am binding label through <Label Content="{Binding Path=OrderDetails.OrderPaymentId}" FontSize="20"> now i want if the value of OrderDetails.OrderPaymentId=0 then the visibility of label become collapsed please help how to do this using style or trigger

            K Offline
            K Offline
            Kunal Chowdhury IN
            wrote on last edited by
            #5

            You can try both the Solution given above. Both are perfect answer.

            Appreciate you for Voting Up my Articles & Forum posts. Mark as Answer if this post Answered your query.


            Regards - Kunal Chowdhury | Software Developer | Blog | Twitter | Silverlight Tutorial | Indian Forum

            1 Reply Last reply
            0
            • I Ian Shlasko

              Or, like John said, write a value converter... 1) Create a class that inherits from IValueConverter 2) Implement the Convert function such that it returns Visibility.Collapsed for 0, or Visibility.Visible for anything else. 3) Create an instance of that class in your resources section in the XAML, and give it a key 4) Reference it in the binding: {Binding OrderDetails.OrderPaymentId,Converter={StaticResource MyConverter}}

              Proud to have finally moved to the A-Ark. Which one are you in?
              Author of the Guardians Saga (Sci-Fi/Fantasy novels)

              D Offline
              D Offline
              devvvy
              wrote on last edited by
              #6

              Converter works:

              <UserControl.Resources>
              <BooleanToVisibilityConverter x:Key="MyBooleanToVisibilityConverter" />
              </UserControl.Resources>

              ...

              <Button Name="btnSomeButton" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="0" Click="btnSomeButton_Click" Width="40px" Height="40px" Visibility="{Binding Path=bIsVisible, ElementName=SomeControl, Mode=TwoWay}" >
              <Image Source="..\Icons\SomeIcon.jpeg" ToolTip="SomeButton" />
              </Button>

              In above example, bIsVisible is a simple CLR property of type Boolean. But as with any other "Enum", you do NOT need a converter, you could have binded a property of type "System.Windows.Visibility" directly to your control:

              <Button Name="btnSomeCmd" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="3" Click="btnSomeCommand_Click" Width="40px" Height="40px" Visibility="{Binding Path=SomeButtonVisibility, ElementName=SomeControl, Mode=TwoWay, diagnostics:PresentationTraceSources.TraceLevel=High}" >
              <Image Source="..\Icons\...; ToolTip="SomeCommand" />
              </Button>

              In above example, SomeButtonVisibility is a dependency property of type System.Windows.Visibility. I used a Dependency Property as supposed to a common CLR property only because I want take advantage of "Two Way" notification.

              dev

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups