Converterparameter xaml wpf




















I like the multi-value converter, offered by Odyth. If you do not have the ability to composite the values, this would be the way to go. I was able to build a class-within-a-class so I could composite my values then pass in one binding value and cast it withing the converter. In M-V-VM, that's the type of data-shaping we should be doing.

My issue was the inability to databind the ConverterParameter, as it is a value type and only takes literals, ugh! I made my Converter work harder, by passing in a 'string literal' for the binding I was doing BorderThickness or BorderBrush and then using an Enum inside of my converter, and casting to it.

This way I have a converter that can bind multiple values, needed for evaluation, and work for multiple scenarios. The value type that you pass into the IValueConverter does not have to match the type that is going to be returned by the converter. For example, I have a custom class UserModel that has a byte[] for the user's photo. If the length of the byte[] is 0, I want to show a silhouette instead of an empty image.

I have two silhouettes. One for Male and one for Female. The UserModel has all the attributes needed to determine which photo to display. I just passed in the entire UserModel instance to the converter and it returns a byte[] based on the UserModel.

Ask a question. Quick access. Search related threads. Remove From My Forums. Answered by:. Archived Forums. Sign in to vote. I would like to make a textblock display the remaining time of an operation. Why isn't the inner Binding evaluated and its value passed to the outter binding ConverterParameter? As seen from the problem definition in the first few paragraphs, this would not have been possible by using a simple binding with a simple IValueConverter and a ConverterParameter property.

There you have it. Please let me know what you think of the article in the comment below. It helps with feedback and better content for you guys next time. Your email address will not be published. Many thanks, Damien. However you cannot use binding in combination with ConverterParameter. You could use a MultiValueConverter and bind to the Engine and your other property as suggested by chriga or programmatically create the Binding object and set the value of its ConverterParameter property:.

Since we haven't heard from you for a long time, I temporarily close this case. If you have any concerns, please free feel to reopen it or submit a new question. We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. ConverterParameter has no specific type it's just an object so the parser does not know what conversion to apply, hence every literal is just treated as a string.

Don't use value. Use: Convert. ToInt32 parameter. Aliostad Aliostad Why don't you want to use value. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.

The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta.



0コメント

  • 1000 / 1000