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. IValueConverter, xaml problem

IValueConverter, xaml problem

Scheduled Pinned Locked Moved WPF
wpfcsharpcsswcfhelp
7 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.
  • M Offline
    M Offline
    marca292
    wrote on last edited by
    #1

    Hi, I am working with a WPF project and have a string property Address.

    StackPanel Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="2,2,10,2" Visibility="{Binding Address, Converter = {StaticResource FormatAddress}}"

    The converter FormatAddress is returning Visibility.Visible if Address is !string.Empty and !="". Can I use this converter if I want show the StackPanel if the Address is string.Empty or ""? Or do I have to create a new converter for this case? Regards Olof

    P V A 3 Replies Last reply
    0
    • M marca292

      Hi, I am working with a WPF project and have a string property Address.

      StackPanel Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="2,2,10,2" Visibility="{Binding Address, Converter = {StaticResource FormatAddress}}"

      The converter FormatAddress is returning Visibility.Visible if Address is !string.Empty and !="". Can I use this converter if I want show the StackPanel if the Address is string.Empty or ""? Or do I have to create a new converter for this case? Regards Olof

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Why not just use string.IsNullOrWhitespace in the converter to decide whether the string is empty or not?

      I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

      Forgive your enemies - it messes with their heads

      My blog | My articles | MoXAML PowerToys | Onyx

      A 1 Reply Last reply
      0
      • P Pete OHanlon

        Why not just use string.IsNullOrWhitespace in the converter to decide whether the string is empty or not?

        I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Onyx

        A Offline
        A Offline
        Abhinav S
        wrote on last edited by
        #3

        He can, provided he is using .Net 4.0. As far as I remember (from a previous discussion), this does not exist in versions before 4.0.

        The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.

        P 1 Reply Last reply
        0
        • A Abhinav S

          He can, provided he is using .Net 4.0. As far as I remember (from a previous discussion), this does not exist in versions before 4.0.

          The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          True, but it's easy to replicate the logic.

          public static bool IsNullOrWhitespace(this string text)
          {
          if (string.IsNullOrEmpty(text))
          return true;
          return text.Trim() == string.Empty;
          }

          I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

          Forgive your enemies - it messes with their heads

          My blog | My articles | MoXAML PowerToys | Onyx

          A 1 Reply Last reply
          0
          • P Pete OHanlon

            True, but it's easy to replicate the logic.

            public static bool IsNullOrWhitespace(this string text)
            {
            if (string.IsNullOrEmpty(text))
            return true;
            return text.Trim() == string.Empty;
            }

            I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Onyx

            A Offline
            A Offline
            Abhinav S
            wrote on last edited by
            #5

            :thumbsup:

            The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.

            1 Reply Last reply
            0
            • M marca292

              Hi, I am working with a WPF project and have a string property Address.

              StackPanel Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="2,2,10,2" Visibility="{Binding Address, Converter = {StaticResource FormatAddress}}"

              The converter FormatAddress is returning Visibility.Visible if Address is !string.Empty and !="". Can I use this converter if I want show the StackPanel if the Address is string.Empty or ""? Or do I have to create a new converter for this case? Regards Olof

              V Offline
              V Offline
              venugopalm
              wrote on last edited by
              #6

              Yes. You can just use the same converter. make sure that your converter always returns Visibility type instead null or string.

              MVVM devotee :)

              1 Reply Last reply
              0
              • M marca292

                Hi, I am working with a WPF project and have a string property Address.

                StackPanel Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Margin="2,2,10,2" Visibility="{Binding Address, Converter = {StaticResource FormatAddress}}"

                The converter FormatAddress is returning Visibility.Visible if Address is !string.Empty and !="". Can I use this converter if I want show the StackPanel if the Address is string.Empty or ""? Or do I have to create a new converter for this case? Regards Olof

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #7

                You could probably use a trigger. You can set visibility based on the true/false.

                [Forum Guidelines]

                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