Channel9Downloader.Controls.AdornedControl.CreateAdornedFrameworkElementFromDataTemplateInResources C# (CSharp) Method

CreateAdornedFrameworkElementFromDataTemplateInResources() private method

Creates the adorned framework element by searching for a DataTemplate that has the same type as the AdornerContent.
        private void CreateAdornedFrameworkElementFromDataTemplateInResources()
        {
            foreach (var resourceDictionary in Application.Current.Resources.MergedDictionaries)
            {
                foreach (var resource in resourceDictionary.Values.OfType<DataTemplate>())
                {
                    if ((Type)resource.DataType == AdornerContent.GetType())
                    {
                        _adornedFrameworkElement = resource.LoadContent() as FrameworkElement;
                        if (_adornedFrameworkElement != null)
                        {
                            _adornedFrameworkElement.DataContext = AdornerContent;
                        }
                    }
                }
            }
        }