0

I'm working on the iOS part of a Xamarin project and am using the XCode interface designer for the UI. For the data-binding of the interface elements we are using MvvmCross and now I'm facing the following issue:

I'm binding the text/label of an UITextView and a UIButton and that works fine. However, the font I've setup for these elements in the interface designer is reset if I apply the binding. (Both font-type and font-color are reset to the default font and color.) If I remove the binding, then I see font and color on the mobile device as configured in the designer. I'm using the following lines to setup the binding:

this.CreateBinding(this.theText).For("Text")
    .To((theViewModel vm) => vm.TextSource)
    .WithConversion(new MvxLanguageConverter(), "theText")
    .Apply();

this.CreateBinding(this.theButton)
    .To((theViewModel vm) => vm.theButtonCommand)
    .Apply();

this.CreateBinding(this.theButton).For("Title")
    .To((theViewModel vm) => vm.TextSource)
    .WithConversion(new MvxLanguageConverter(), "theButton")
    .Apply();

Is there a way to set this up so that font and color are preserved? If not I can setup these elements in code, but I prefer to do the design in the designer as much as possible.

Thanks! Olaf

PS. see comments, this is apparently not related to data-binding using MvvmCross. However, the proposed solutions in the other post basically suggest to make a new attributed string using the existing attributes and I don't see how you would do this using binding.

Olaf Donk
  • 21
  • 3
  • If you remove the binding and just set the `Text` in code like `this.theText.Text = "Hello";` do you see the same font/color reset? – Stuart Nov 18 '14 at 10:22
  • 1
    My guess is that somehow you using attributedText in Interface Builder - similar to http://stackoverflow.com/questions/14488069/changing-uilabel-text-but-keeping-the-rest-of-the-attributes - you should be able to set the properties on the UILabel and then use non-attributed text instead – Stuart Nov 18 '14 at 10:32
  • Thanks @Stuart, you're probably right, if I change the Text property directly (without binding) the font and color also get lost. So it looks like the design uses attributed text. (Which I find strange, as I've setup the view to use plain text.) I'll do some further research on attributed versus non-attributed text, meanwhile if anyone knows how to circumvent this 'feature'... ;-) – Olaf Donk Nov 18 '14 at 12:52

0 Answers0