我有一个MvxBaseBindableCollectionViewCell,它加载一个包含自定义按钮的xib。我希望能够将此自定义按钮传递给要绑定的ViewModel。这可能吗?
我正在努力实现像MyButton.ViewModel = ViewModel.ChildViewModel
之类的东西,并将ViewModel.ChildViewModel.Name显示为按钮标题。
答案 0 :(得分:2)
如果你想自定义绑定一个单元格,那么http://slodge.blogspot.co.uk/2013/01/uitableviewcell-using-xib-editor.html
就有了这方面的教程如果要在该视图中创建完全可绑定的UIButton,则可以使用以下某些继承来执行此操作:
[Register("MyButton")]
public class MyButton
: UIButton
, IMvxServiceConsumer
{
private IList<IMvxUpdateableBinding> _bindings;
private const string BindingText = "SpecialTitle Customer.Name";
public MyButton()
{
}
public MyButton(IntPtr handle)
: base(handle)
{
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
foreach (var binding in _bindings)
{
binding.Dispose();
}
_bindings.Clear();
}
base.Dispose(disposing);
}
private object _dc;
public object DataContext
{
get { return _dc; }
set
{
_dc = value;
if (_bindings == null)
{
var binder = this.GetService<IMvxBinder>();
_bindings = binder.Bind(_dc, this, BindingText).ToList();
}
else
{
foreach (var binding in _bindings)
{
binding.DataContext = _dc;
}
}
}
}
public string SpecialTitle
{
get { return this.GetTitle(UIControlState.Normal); }
set { this.SetTitle(value, UIControlState.Normal); }
}
}
除了&gt; MvvmCross v3“Hot Tuna”将包含一些帮助程序类,以使其更简单。