Exemple #1
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _list = (MtListBox)GetTemplateChild("List");
            _grid = (Grid)GetTemplateChild("Grid");

            _translate = (TranslateTransform)GetTemplateChild("Translate");
            _story     = (Storyboard)GetTemplateChild("Story");

            _list.ItemsSource       = Items;
            _list.SelectionChanged += OnSelectionChanged;

            foreach (var item in Items.Where(i => i.Preload))
            {
                item.Content.Visibility = Visibility.Collapsed;
                AddElement(item.Content);
            }

            _items.CollectionChanged += OnCollectionChanged;

            if (_initialItem != null)
            {
                SelectedItem = _initialItem;
            }
            else if (Items.Count > _initialIndex)
            {
                SelectedItem = _items[_initialIndex];
            }
            else
            {
                SelectedItem = _items.FirstOrDefault();
            }
        }
Exemple #2
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _titleRowControl = (Grid)GetTemplateChild("ColumnHeaders");

            _listControl = (MtListBox)GetTemplateChild("Rows");
            _listControl.PrepareContainerForItem += OnPrepareContainerForItem;

            _listControl.SelectionChanged -= OnSelectionChanged;
            _listControl.SelectionChanged += OnSelectionChanged;

            _listControl.SetBinding(Selector.SelectedItemProperty,
                                    new Binding {
                Source = this, Path = new PropertyPath("SelectedItem"), Mode = BindingMode.TwoWay
            });
            _listControl.SetBinding(ListBox.SelectionModeProperty,
                                    new Binding {
                Source = this, Path = new PropertyPath("SelectionMode"), Mode = BindingMode.TwoWay
            });

            _initialSelectedItem = SelectedItem;

            _listControl.ScrolledToEnd -= ScrolledToEnd;
            _listControl.ScrolledToEnd += ScrolledToEnd;

            if (DefaultOrderIndex == -1)
            {
                var currentOrdered = Columns.FirstOrDefault(c => c.CanSort);
                if (currentOrdered != null)
                {
                    DefaultOrderIndex = Columns.IndexOf(currentOrdered);
                }
                else
                {
                    DefaultOrderIndex = 0;
                }
            }

            Initialize();
        }
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _list = (MtListBox)GetTemplateChild("List");
            _grid = (Grid)GetTemplateChild("Grid");

            _translate = (TranslateTransform)GetTemplateChild("Translate");
            _story = (Storyboard)GetTemplateChild("Story");

            _list.ItemsSource = Items;
            _list.SelectionChanged += OnSelectionChanged;

            foreach (var item in Items.Where(i => i.Preload))
            {
                item.Content.Visibility = Visibility.Collapsed;
                AddElement(item.Content);
            }

            _items.CollectionChanged += OnCollectionChanged;

            if (_initialItem != null)
                _list.SelectedItem = _initialItem;
            else
                _list.SelectedIndex = _initialIndex;
        }