Example #1
0
        /// <summary>The get data from list box.</summary>
        /// <param name="source">The source.</param>
        /// <param name="point">The point.</param>
        /// <returns>The <see cref="object"/>.</returns>
        private static object GetDataFromListBox(ListBox source, Point point)
        {
            var element = source.InputHitTest(point) as UIElement;
            if (element == null)
            {
                return null;
            }

            var data = DependencyProperty.UnsetValue;
            while (data == DependencyProperty.UnsetValue)
            {
                if (element == null)
                {
                    continue;
                }

                data = source.ItemContainerGenerator.ItemFromContainer(element);

                if (data == DependencyProperty.UnsetValue)
                {
                    element = VisualTreeHelper.GetParent(element) as UIElement;
                }

                if (source.Equals(element))
                {
                    return null;
                }
            }

            return data != DependencyProperty.UnsetValue ? data : null;
        }
Example #2
0
        void InitElement(ListBox listBox, List<TagInfo> tagInfos)
        {
            //!!!貌似不起作用
            LogManager.Ins.Log("开始加载数据Tag到UI");
            Thread thread = new Thread(new ThreadStart(() =>
            {
                Dispatcher.BeginInvoke(() =>
                {
                    listBox.Items.Clear();
                    foreach (TagInfo item in tagInfos)
                    {
                        Button button = new Button();
                        button.Style = Application.Current.Resources["TagsButtonStyle"] as Style;
                        button.Foreground = new SolidColorBrush(Colors.White);
                        button.Background = new SolidColorBrush(Colors.White);
                        button.Height = 35;
                        button.Margin = new Thickness(0, 20, 0, 0);
                        button.Content = item.TagName;
                        button.Tag = item;
                        button.Tap += new EventHandler<GestureEventArgs>(button_Tap);
                        if (button.Content.ToString() == "全部")
                            button.Background = new SolidColorBrush(Utils.Utils.GetColor("#FF00AEFF"));
                        listBox.Items.Add(button);
                    }

                    if (listBox.Equals(xCatalogListBox))
                    {
                        xCatalogProgressBar.Visibility = Visibility.Collapsed;
                    }
                    else if (listBox.Equals(xAreaListBox))
                    {
                        xAreaProgressBar.Visibility = Visibility.Collapsed;
                    }
                    else if (listBox.Equals(xYearListBox))
                    {
                        xYearProgressBar.Visibility = Visibility.Collapsed;
                    }
                }
                );
            }));
            thread.IsBackground = true;
            thread.Start();
            LogManager.Ins.Log("加载完数据Tag到UI");
        }
        private ListBoxItem GetListItemByIndex(ListBox parent, int index)
        {
            if (parent.Equals(null)) return null;

            var generator = parent.ItemContainerGenerator;
            if ((index >= 0) && (index < parent.Items.Count))
                return generator.ContainerFromIndex(index) as ListBoxItem;

            return null;
        }