Exemple #1
0
        /// <summary>
        ///  Appies the binding to the breadcrumb item.
        /// </summary>
        public void ApplyBinding()
        {
            object item = DataContext;

            if (item == null)
            {
                return;
            }

            BreadcrumbItem       root             = this;
            DataTemplate         template         = HeaderTemplate;
            DataTemplateSelector templateSelector = HeaderTemplateSelector;

            if (templateSelector != null)
            {
                template = templateSelector.SelectTemplate(item, root);
            }
            if (template == null)
            {
                DataTemplateKey key = GetResourceKey(item);
                if (key != null)
                {
                    template = TryFindResource(key) as DataTemplate;
                }
            }

            root.SelectedItem = null;

            HierarchicalDataTemplate hdt = template as HierarchicalDataTemplate;

            if (template != null)
            {
                root.Header = template.LoadContent();
            }
            else
            {
                root.Header = item;
            }
            root.DataContext = item;

            if (hdt != null)
            {
                // bind the Items to the hierarchical data template:
                root.SetBinding(BreadcrumbItem.ItemsSourceProperty, hdt.ItemsSource);
            }

            BreadcrumbBar bar = BreadcrumbBar;

            if (bar != null)
            {
                if (TraceBinding == null)
                {
                    TraceBinding = bar.TraceBinding;
                }
                if (ImageBinding == null)
                {
                    ImageBinding = bar.ImageBinding;
                }
            }

            if (TraceBinding != null)
            {
                root.SetBinding(BreadcrumbItem.TraceProperty, TraceBinding);
            }
            if (ImageBinding != null)
            {
                root.SetBinding(BreadcrumbItem.ImageProperty, ImageBinding);
            }


            ApplyProperties(item);
        }
Exemple #2
0
        /// <summary>
        /// Generate BarCrum Tree Items
        /// </summary>
        /// <param name="objlist">TreeItem Collection</param>
        private void GenerateBar(IEnumerable <SystemMenuTreeList> objlist)
        {
            try
            {
                Binding languageBinding = new Binding()
                {
                    Source = this,
                    Mode   = BindingMode.TwoWay,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Path = new PropertyPath(BreadcrumbItem.LanguageProperty)
                };

                LocalizeItemSelector localizeItemSelector;
                foreach (var item in objlist)
                {
                    localizeItemSelector = new LocalizeItemSelector();
                    CommonMethods.AddLocalizeItem(localizeItemSelector, "ja", item.NameJa != null ? item.NameJa : PropertyValueNotSet);
                    CommonMethods.AddLocalizeItem(localizeItemSelector, "en", item.NameEn != null ? item.NameEn : PropertyValueNotSet);
                    CommonMethods.AddLocalizeItem(localizeItemSelector, "th", item.NameTh != null ? item.NameTh : PropertyValueNotSet);
                    CommonMethods.AddLocalizeItem(localizeItemSelector, "zh", item.NameTh != null ? item.NameTh : PropertyValueNotSet);

                    if (item.PId == 0)
                    {
                        withChildBreadcrumbItem         = new BreadcrumbItem();
                        withChildBreadcrumbItem.Header  = localizeItemSelector.setLocalizeValue(withChildBreadcrumbItem, BreadcrumbItem.HeaderProperty);
                        withChildBreadcrumbItem.PageUri = item.PageUri;
                        withChildBreadcrumbItem.SetBinding(BreadcrumbItem.LanguageProperty, languageBinding);
                        this.Items.Add(withChildBreadcrumbItem);

                        var Parents1 = ItemSource.OrderBy(p => p.DisplayIndex).Where(p => p.PId == item.Id);
                        if (Parents1.Any())
                        {
                            GenerateBar(Parents1);
                        }
                    }
                    else
                    {
                        withoutChildBreadcrumbItem         = new BreadcrumbItem();
                        withoutChildBreadcrumbItem.PageUri = item.PageUri;
                        withoutChildBreadcrumbItem.SetBinding(BreadcrumbItem.LanguageProperty, languageBinding);
                        withoutChildBreadcrumbItem.Header = localizeItemSelector.setLocalizeValue(withoutChildBreadcrumbItem, BreadcrumbItem.HeaderProperty);

                        if (!DicBreadCrumbItemAddressBar.ContainsKey(item.Id))
                        {
                            DicBreadCrumbItemAddressBar.Add(item.Id, withoutChildBreadcrumbItem);
                        }
                        if (DicBreadCrumbItemAddressBar.ContainsKey(item.PId))
                        {
                            DicBreadCrumbItemAddressBar[item.PId].Items.Add(withoutChildBreadcrumbItem);
                        }
                        else
                        {
                            withChildBreadcrumbItem.Items.Add(withoutChildBreadcrumbItem);
                        }
                        var Parents = ItemSource.OrderBy(p => p.DisplayIndex).Where(p => p.PId == item.Id);
                        if (Parents.Any())
                        {
                            GenerateBar(Parents);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }