Ejemplo n.º 1
0
        private static void TracePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem item = sender as BreadcrumbItem;

            RoutedPropertyChangedEventArgs <object> args = new RoutedPropertyChangedEventArgs <object>(e.OldValue, e.NewValue, TraceChangedEvent);

            item.RaiseEvent(args);
        }
Ejemplo n.º 2
0
        void contextMenu_Opened(object sender, RoutedEventArgs e)
        {
            contextMenu.Items.Clear();
            contextMenu.ItemTemplate         = ItemTemplate;
            contextMenu.ItemTemplateSelector = ItemTemplateSelector;
            foreach (object item in Items)
            {
                if (!(item is MenuItem) && !(item is Separator))
                {
                    MenuItem menuItem = new MenuItem();
                    menuItem.DataContext = item;
                    BreadcrumbItem bi = item as BreadcrumbItem;
                    if (bi == null)
                    {
                        BreadcrumbItem parent = TemplatedParent as BreadcrumbItem;
                        if (parent != null)
                        {
                            bi = parent.ContainerFromItem(item);
                        }
                    }
                    if (bi != null)
                    {
                        menuItem.Header = bi.TraceValue;
                    }

                    Image image = new Image();
                    image.Source = bi != null ? bi.Image : null;
                    image.SnapsToDevicePixels = true;
                    image.Stretch             = Stretch.Fill;
                    image.VerticalAlignment   = VerticalAlignment.Center;
                    image.HorizontalAlignment = HorizontalAlignment.Center;
                    image.Width  = 16;
                    image.Height = 16;

                    menuItem.Icon = image;

                    menuItem.Click += new RoutedEventHandler(item_Click);
                    if (item != null && item.Equals(SelectedItem))
                    {
                        menuItem.FontWeight = FontWeights.Bold;
                    }
                    menuItem.ItemTemplate         = ItemTemplate;
                    menuItem.ItemTemplateSelector = ItemTemplateSelector;
                    contextMenu.Items.Add(menuItem);
                }
                else
                {
                    contextMenu.Items.Add(item);
                }
            }
            contextMenu.Placement       = PlacementMode.Relative;
            contextMenu.PlacementTarget = dropDownBtn;
            contextMenu.VerticalOffset  = dropDownBtn.ActualHeight;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new BreadcrumbItem out of the specified data.
        /// </summary>
        /// <param name="dataContext">The DataContext for the BreadcrumbItem</param>
        /// <returns>DataContext if dataContext is a Breadcrumbitem, otherwhise a new BreadcrumbItem.</returns>
        public static BreadcrumbItem CreateItem(object dataContext)
        {
            BreadcrumbItem item = dataContext as BreadcrumbItem;

            if (item == null && dataContext != null)
            {
                item             = new BreadcrumbItem();
                item.DataContext = dataContext;
            }
            return(item);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Generates a new BreadcrumbItem out of the specified item.
        /// </summary>
        /// <param name="item">The item for which to create a new BreadcrumbItem.</param>
        /// <returns>Item, if item is a BreadcrumbItem, otherwhise a newly created BreadcrumbItem.</returns>
        public BreadcrumbItem ContainerFromItem(object item)
        {
            BreadcrumbItem result = item as BreadcrumbItem;

            if (result == null)
            {
                result = CreateItem(item);
                if (result != null)
                {
                    AddLogicalChild(result);
                    result.ApplyTemplate();
                }
            }
            return(result);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Gets the item that represents the specified trace otherwise null.
 /// </summary>
 /// <param name="trace">The Trace property of the associated BreadcrumbItem.</param>
 /// <returns>An object included in Items, otherwise null.</returns>
 public object GetTraceItem(string trace)
 {
     //this.ApplyTemplate();
     foreach (object item in Items)
     {
         BreadcrumbItem bcItem = ContainerFromItem(item);
         if (item != null)
         {
             //ApplyProperties(item);
             string value = bcItem.TraceValue;
             if (value != null && value.Equals(trace, StringComparison.InvariantCultureIgnoreCase))
             {
                 return(item);
             }
         }
         else
         {
             return(null);
         }
     }
     return(null);
 }
 public BreadcrumbItemEventArgs(BreadcrumbItem item, RoutedEvent routedEvent)
     : base(routedEvent)
 {
     Item = item;
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Occurs when the Overflow property is changed.
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        public static void OverflowPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem item = d as BreadcrumbItem;

            item.OnOverflowChanged((bool)e.NewValue);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Occurs when the IsDropDownPressed property is changed.
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        public static void DropDownPressedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem item = d as BreadcrumbItem;

            item.OnDropDownPressedChanged();
        }
Ejemplo n.º 10
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            BreadcrumbItem item = new BreadcrumbItem();

            return(item);
        }
Ejemplo n.º 11
0
        private static void SelectedBreadcrumbPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            BreadcrumbItem item = d as BreadcrumbItem;

            item.OnSelectedBreadcrumbChanged(e.OldValue, e.NewValue);
        }
Ejemplo n.º 12
0
 private static void HeaderPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
 {
     BreadcrumbItem item = sender as BreadcrumbItem;
 }
Ejemplo n.º 13
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;
            }
        }