1

we are using MVVMCross and we are having trouble binding an NSAttributedString to a UITextView. It's weird because the same code works without using a BindingSet and also using Bindig for Text property instead of AttributedText

As said, this line of code is not binding, the TextView just shows the default text:

set.Bind (TxtActivityText).For(txt => txt.AttributedText).To (vm => vm.Activity).WithConversion("ActivitySpanMessage");

... and outputs the following warning: "MvxBind:Warning: 6.06 Failed to create target binding for binding AttributedText for Activity"

While with this line is working fine:

set.Bind (TxtActivityText).For(txt => txt.Text).To (vm => vm.Activity).WithConversion("ActivitySpanMessage"); // Works fine also binding to the default property

And finally, without using bindings it works fine too:

TxtActivityText.AttributedText = SpanMessageHelper.ConvertToAttributedString(ViewModel.Activity, null, null, null); // This function is the same I call in the ActivitySpanMessageConverter

Any ideas? May this be a bug?

3
  • Is there any debug information in trace? Is there any more info you can provide in the question - e.g. some code values that are used? it "may be a bug"(TM) but others have seen Attributed Text binding working fine - eg. stackoverflow.com/questions/17934294/… and github.com/MvvmCross/MvvmCross/issues/791
    – Stuart
    Dec 18, 2014 at 18:20
  • Yes, it says MvxBind:Warning: 6.06 Failed to create target binding for binding AttributedText for Activity. It's weird because it's a pretty simple casa: simple XIB done with xCode6 with some other controls working fine. Tomorrow I'll try if its a problem with the simulator Dec 18, 2014 at 19:05
  • Please edit the question to include the relevant trace and information - it's easier to read in the question than it is in the comments. Thanks.
    – Stuart
    Dec 18, 2014 at 20:21

1 Answer 1

5

This is probably because the Xamarin linker is not including UITextView.AttributedText since it is only used in an expression. See this post for more info: MvvmCross Failed to create target binding for EditingDidBegin on iPhone

You can fix this by going to LinkerPleaseInclude.cs and changing your UITextView include method:

public void Include(UITextView textView)
{
    textView.Text = textView.Text + "";
    textView.Changed += (sender, args) => { textView.Text = ""; };

    // Add this line here
    textView.AttributedText = new NSAttributedString();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.