コード例 #1
0
        public static T GetTemplateChild <T>(this ITemplatedControl control, string name) where T : INamed
        {
            var result = control.FindTemplateChild <T>(name);

            if (result == null)
            {
                throw new InvalidOperationException(string.Format(
                                                        "Could not find template child '{0}' of type '{1}' in template for '{2}'.",
                                                        name,
                                                        typeof(T).FullName,
                                                        control.GetType().FullName));
            }

            return(result);
        }