telerik/xaml-sdk

Prism Examples

Css-IanM opened this issue · 7 comments

Would it be reasonable to request updated prism examples where applicable? The given examples are severely dated. I wouldn't be against a PR or two, though my open source time is limited. I work with both telerik products and prism daily.

Hello Css-IanM,

If you would specify which examples you're refering to, I'd be more than happy to create backlog items for improving them and we will try to update them as soon as possible.

Thank you in advance for your cooperation on the matter.

Docking This example is just outdated.
OutlookBar Example would be nice. I've wrote a region adapter for this already but others would find it useful I imagine.
RibbonView Example would be nice here as well. I've already wrote another region adapter for this as well, but for others and future reference it would be nice to be included.
TabControl This is another reference that exists but is pretty outdated.

Thank you for the list of examples that need update.

I've gone ahead and logged a new item in our backlog regarding them. Would you find it possible to share the adapters you've already implemented for reference?

Thank you once more for your contribution :)

As requested.

RadOutlookBar Region Adapter

 public class RadOutlookBarRegionAdapter : RegionAdapterBase<RadOutlookBar>
    {
        public RadOutlookBarRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) : base(regionBehaviorFactory)
        {
        }

        protected override void Adapt(IRegion region, RadOutlookBar regionTarget)
        {
            region.Views.CollectionChanged += (s, e) =>
            {
                switch (e.Action)
                {
                    case NotifyCollectionChangedAction.Add:
                        {
                            foreach (var group in e.NewItems)
                            {
                                regionTarget.Items.Add(group);
                                // Automatically select first item.
                                if (regionTarget.Items[0] == group)
                                {
                                    regionTarget.SelectedItem = group;
                                }
                            }
                        }
                        break;
                    case NotifyCollectionChangedAction.Remove:
                        {
                            foreach (var group in e.OldItems)
                            {
                                regionTarget.Items.Remove(group);
                            }
                        }
                        break;
                    default:
                        break;
                }
            };
        }

        protected override IRegion CreateRegion()
        {
            return new SingleActiveRegion();
        }
    }

RadRibbon Region Adapter

 public class RadRibbonRegionAdapter : RegionAdapterBase<RadRibbonView>
    {
        public RadRibbonRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) : base(regionBehaviorFactory)
        {
        }

        protected override void Adapt(IRegion region, RadRibbonView regionTarget)
        {
            if (region == null) throw new ArgumentNullException(nameof(region));
            if (regionTarget == null) throw new ArgumentNullException(nameof(regionTarget));

            region.Views.CollectionChanged += (s, e) =>
            {
                if (e.Action == NotifyCollectionChangedAction.Add)
                {
                    foreach (var view in e.NewItems)
                    {
                        AddViewToRegion(view, regionTarget);
                    }
                }
                else if (e.Action == NotifyCollectionChangedAction.Remove)
                {
                    foreach (var view in e.OldItems)
                    {
                        RemoveViewFromRegion(view, regionTarget);
                    }
                }
             };
        }

        protected override IRegion CreateRegion()
        {
            return new SingleActiveRegion();
        }

        static void AddViewToRegion(object view, RadRibbonView radRibbonView)
        {
            if (view is RadRibbonTab ribbonTabItem)
            {
                radRibbonView.Items.Add(ribbonTabItem);
            }
        }

        static void RemoveViewFromRegion(object view, RadRibbonView radRibbonView)
        {
            if (view is RadRibbonTab ribbonTabItem)
            {
                radRibbonView.Items.Remove(view);
            }
        }
    }

Thank you very much!

We will try to use these regions in the updated examples if possible.

Although I cannot commit to a certain time frame for this improvement, we will update this issue when we make changes to the examples, so you should get notified about this if you're following the issue.

If you have any other questions or concerns in the meantime, do not hesitate to ask.

Our project uses prism Framework version 7.2.0.1367, and telerik uses version 2019.3.1023.45. The main interface uses docking in the example. After opening some pages (TAB), close all pages, and then reopen the page, there are exceptions.
The abnormal contents are as follows:

Prism.Regions.UpdateRegionsException :“An exception occurred while trying to create region objects.

  • The most likely causing exception was: ' System.Reflection.TargetInvocationException : an exception occurred at the target of the call. ---> Prism.Regions.UpdateRegionsException : An exception occurred while trying to create region objects.

  • The most likely causing exception was: ' System.Reflection.TargetInvocationException : an exception occurred at the target of the call. ---> Prism.Regions.Behaviors .RegionCreationException: An exception occurred while creating a region with name ''. The exception was: System.ArgumentNullException : value cannot be null.

Parameter name: regionname

In Prism.Regions.RegionAdapterBase `1.Initialize(T regionTarget, String regionName)

In Prism.Regions.RegionAdapterBase `1. Prism.Regions.IRegionAdapter .Initialize(Object regionTarget, String regionName)

In Prism.Regions.Behaviors .DelayedRe gionCreationBehavior.CreateRegion (DependencyObject targetElement, String regionName). ---> System.ArgumentNullException : value cannot be null.

Parameter name: regionname

In Prism.Regions.RegionAdapterBase `1.Initialize(T regionTarget, String regionName)

In Prism.Regions.RegionAdapterBase `1. Prism.Regions.IRegionAdapter .Initialize(Object regionTarget, String regionName)

In Prism.Regions.Behaviors .DelayedRe gionCreationBehavior.CreateRegion (DependencyObject targetElement, String regionName)

---The end of the inner exception stack trace---

In Prism.Regions.Behaviors .DelayedRe gionCreationBehavior.CreateRegion (DependencyObject targetElement, String regionName)

In Prism.Regions.Behaviors .DelayedRe gionCreationBehavior.TryCreateRegion ()

In Prism.Regions.Behaviors .DelayedRe gionCreationBehavior.OnUpdatingRegions (Object sender, EventArgs e)

---The end of the inner exception stack trace---

In System.RuntimeMethodHandle.InvokeMethod (Object target, Object[] arguments, Signature sig, Boolean constructor)

In System.Reflection.RuntimeMethodInfo .UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

In System.Delegate.DynamicInvokeImpl (Object[] args)

In Prism.Events.WeakDelegatesManager .Raise(Object[] args)

In Prism.Regions.RegionManager .UpdateRegions()'.

But also check the InnerExceptions for more detail or call .GetRootException(). ---> Prism.Regions.Behaviors .RegionCreationException: An exception occurred while creating a region with name ''. The exception was: System.ArgumentNullException : value cannot be null.

Parameter name: regionname

In Prism.Regions.RegionAdapterBase `1.Initialize(T regionTarget, String regionName)

In Prism.Regions.RegionAdapterBase `1. Prism.Regions.IRegionAdapter .Initialize(Object regionTarget, String regionName)

In Prism.Regions.Behaviors .DelayedRe gionCreationBehavior.CreateRegion (DependencyObject targetElement, String regionName). ---> System.ArgumentNullException : value cannot be null.

Parameter name: regionname

In Prism.Regions.RegionAdapterBase `1.Initialize(T regionTarget, String regionName)

In Prism.Regions.RegionAdapterBase `1. Prism.Regions.IRegionAdapter .Initialize(Object regionTarget, String regionName)

In Prism.Regions.Behaviors .DelayedRe gionCreationBehavior.CreateRegion (DependencyObject targetElement, String regionName)

---The end of the inner exception stack trace---

In Prism.Regions.Behaviors .DelayedRe gionCreationBehavior.CreateRegion (DependencyObject targetElement, String regionName)

In Prism.Regions.Behaviors .DelayedRe gionCreationBehavior.TryCreateRegion ()

In Prism.Regions.Behaviors .DelayedRe gionCreationBehavior.OnUpdatingRegions (Object sender, EventArgs e)

---The end of the inner exception stack trace---

In Prism.Regions.RegionManager .UpdateRegions()

In Prism.Regions.RegionManager . RegionCollection.Remove (String regionName)

In Prism.Regions.Behaviors .RegionManager RegistrationBehavior.TryRegisterRegion ()

In Prism.Regions.Behaviors .RegionManager RegistrationBehavior.OnUpdatingRegions (Object sender, EventArgs e)

---The end of the inner exception stack trace---

In System.RuntimeMethodHandle.InvokeMethod (Object target, Object[] arguments, Signature sig, Boolean constructor)

In System.Reflection.RuntimeMethodInfo .UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

In System.Delegate.DynamicInvokeImpl (Object[] args)

In Prism.Events.WeakDelegatesManager .Raise(Object[] args)

In Prism.Regions.RegionManager .UpdateRegions()'.

But also check the InnerExceptions for more detail or call .GetRootException(). ”

Hello,

Can you tell me which SDK example you are referring to?

Regards,
Martin Ivanov
Telerik WPF Team