Пример #1
0
        public PagingView(IPagingViewModel viewModel)
        {
            InitializeComponent();

            viewModel.SetParentView(this);

            DataContext = viewModel;
        }
Пример #2
0
        private static void ViewModel_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            IPageInfo pageInfo = d as IPageInfo;

            if (pageInfo == null)
            {
                return;
            }

            IPagingViewModel vm = e.OldValue as IPagingViewModel;

            if (vm != null)
            {
                pageInfo.UnNotifyOn("PageCount");
                pageInfo.UnNotifyOn("CurrentPageRect");
            }

            vm = e.NewValue as IPagingViewModel;
            if (vm != null)
            {
                pageInfo.NotifyOn("PageCount", (newValue, oldValue) =>
                {
                    vm.TotalPages = (int)newValue;
                    if (vm.TotalPages > 0)
                    {
                        vm.RestoreSelection();
                    }
                });
                pageInfo.NotifyOn("CurrentPageRect", (newValue, oldValue) =>
                {
                    Rect rect = (Rect)newValue;
                    if (rect.IsEmpty)
                    {
                        return;
                    }
                    vm.PageWidth = rect.Width;
                    vm.PageLeft  = rect.Left;
                });
                var binding = new Binding("CurrentPage")
                {
                    Source = vm,
                    Mode   = BindingMode.TwoWay
                };
                BindingOperations.SetBinding(d, VirtualizingSmartPanel.CurrentPageProperty, binding);
                var element = d as FrameworkElement;
                if (element != null)
                {
                    element.Unloaded += (sender, args) =>
                    {
                        BindingOperations.ClearBinding((DependencyObject)sender, VirtualizingSmartPanel.CurrentPageProperty);
                    };
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Sets the view model.
 /// </summary>
 /// <param name="obj">The dependency object.</param>
 /// <param name="value">The value.</param>
 public static void SetViewModel(DependencyObject obj, IPagingViewModel value)
 {
     obj.SetValue(ViewModelProperty, value);
 }
Пример #4
0
 /// <summary>
 /// Sets the view model.
 /// </summary>
 /// <param name="obj">The dependency object.</param>
 /// <param name="value">The value.</param>
 public static void SetViewModel(DependencyObject obj, IPagingViewModel value)
 {
     obj.SetValue(ViewModelProperty, value);
 }