Results 1 to 4 of 4

Thread: [RESOLVED] FallbackValue Binding

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Resolved [RESOLVED] FallbackValue Binding

    Can you have a FallbackValue be set to another property using data binding?

    For example, I have a label that's default value will be coming from the DisplayName property however, if it's not populated I'd like to revert to the Name property on the same object.

    Code:
    <Label Grid.Column="0" Content="{Binding DisplayName, Mode=Default}"/>

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: FallbackValue Binding

    You could maybe use a Converter - dont know if you are familiar with them but basically using a Converter would mean that a specific method in your code gets called each time that binding is used and the value that is going to be used for the binding gets passed in to your code, so you could just check it and see if it is empty. If it is empty then you return the value of the Name property on whatever object you are talking about.
    One situation where this might not work very well is if the object you are trying to bind to is not very easily accessible from your code (ie something automatically generated by a XAML DataTemplate or similar) - though I think it still would not be impossible, just a bit harder to get working reliably.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: FallbackValue Binding

    For those that are interested, I ended up having to create a IValueConverter to handle this situation.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  4. #4
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [RESOLVED] FallbackValue Binding

    You mean exactly what I just described?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width