Ask a questionAsk a question
 

AnswerHow to make Width to Auto in a binding?

  • Wednesday, November 04, 2009 2:44 AMZach_Shine Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hello all,

    I have a UserControl and binds its Width property to a property of my own model class. The XMAL I'm using is :

    <UserControl Width={Binding ModelWidth, Mode=TwoWay}/>
    
    

    The ModelWidth is a normal CLR property where its type is double.
    Normally it works fine.

    However, now I want to make the width of the UserControl to "auto" if the value of ModelWidth is double.NaN.

    I know there is a way to make a usercontrol to "auto" by C# code:
    usercontrol.ClearValue(FrameworkElement.WidthProperty);
    
    The best way I think is to use pure XAML + Converters. How can I achieve this?

    Best regards,
    Zach

Answers

All Replies