/// <summary> /// Binds RxProperties to View Model /// Note that the view model shall implements IPropertyChangedProxy /// Refer to doc for details /// </summary> /// <param name="viewModel"></param> /// <param name="view"></param> public static void BindRxPropertiesToView(this IPropertyChangedProxy viewModel, object view) { var rxProperties = new List <string>(); // Holds all RxProperties names var typeOfThis = viewModel.GetType(); var allProp = typeOfThis.GetProperties(); // Bind all properties to view model allProp.ToList().ForEach(p => { if (p.GetValue(viewModel) is IPropertyToBind propertyToBind) // Get only IPropertyToBind (RxProperty) { propertyToBind.BindToView(viewModel, p.Name); rxProperties.Add(p.Name); } }); // Update the Binding path from RxProperty name to name.Value (allows TwoWay binding mode) DoOnAllBindings(view as FrameworkElement, binding => { var path = binding.Path?.Path; if (rxProperties.Contains(path)) { binding.Path.Path += ".Value"; } }); }
public void BindToView(IPropertyChangedProxy parent, string propertyName) { _parent = parent; _eventArgs = new PropertyChangedEventArgs(propertyName); }