/// <summary>
        /// Wires a control to a property.
        /// This should be called in the Fragment's OnCreateView, with the newly inflated layout.
        /// </summary>
        /// <param name="fragment">The fragment.</param>
        /// <param name="inflatedView">The inflated view.</param>
        /// <param name="resolveMembers">The resolve members.</param>
        public static void WireUpControls(this Fragment fragment, View inflatedView, ResolveStrategy resolveMembers = ResolveStrategy.Implicit)
        {
            if (fragment is null)
            {
                throw new ArgumentNullException(nameof(fragment));
            }

            var members = fragment.GetWireUpMembers(resolveMembers);

            foreach (var member in members)
            {
                try
                {
                    // Find the android control with the same name from the view
                    var view = inflatedView.GetControl(fragment.GetType().Assembly, member.GetResourceName());

                    // Set the activity field's value to the view with that identifier
                    member.SetValue(fragment, view);
                }
                catch (Exception ex)
                {
                    throw new
                          MissingFieldException("Failed to wire up the Property " + member.Name + " to a View in your layout with a corresponding identifier", ex);
                }
            }
        }
Exemple #2
0
        private static TFragment SafeCast <TFragment>(Fragment fragment) where TFragment : Fragment
        {
            if (!(fragment is TFragment))
            {
                MvxLogHost.Default?.Log(LogLevel.Warning,
                                        "Fragment type mismatch got {fragmentType} but expected {expectedType}",
                                        fragment.GetType().FullName, typeof(TFragment).FullName);
                return(default(TFragment));
            }

            return((TFragment)fragment);
        }
Exemple #3
0
        private static TFragment SafeCast <TFragment>(Fragment fragment) where TFragment : Fragment
        {
            if (!(fragment is TFragment))
            {
                MvxLog.Instance.Warn("Fragment type mismatch got {0} but expected {1}", fragment.GetType().FullName,
                                     typeof(TFragment).FullName);
                return(default(TFragment));
            }

            return((TFragment)fragment);
        }