/// <summary>
 /// Binds <see cref="DataPresenter"/> to <see cref="CheckBox"/> to select/deselect all rows.
 /// </summary>
 /// <param name="dataPresenter">The <see cref="DataPresenter"/></param>
 /// <returns>The scalar binding object.</returns>
 public static ScalarBinding <CheckBox> BindToCheckBox(this DataPresenter dataPresenter)
 {
     return(ToSelectAll <CheckBox>(dataPresenter));
 }
示例#2
0
 private bool ConfirmEndEdit()
 {
     return(DataPresenter == null ? true : DataPresenter.ConfirmEndEdit());
 }
示例#3
0
 public void Initialize(DataPresenter dataPresenter)
 {
     DataPresenter = dataPresenter;
 }
        private static ScalarBinding <T> ToSelectAll <T>(this DataPresenter dataPresenter)
            where T : ToggleButton, new()
        {
            if (dataPresenter == null)
            {
                throw new ArgumentNullException(nameof(dataPresenter));
            }

            var trigger = new PropertyChangedTrigger <T>(ToggleButton.IsCheckedProperty).WithAction(v =>
            {
                var binding = (TwoWayBinding)v.GetBinding();
                if (binding.IsRefreshing)
                {
                    return;
                }
                var isChecked = v.IsChecked;
                if (!isChecked.HasValue)
                {
                    return;
                }

                var isSelected = isChecked.GetValueOrDefault();
                var rows       = dataPresenter.Rows;
                bool anyChange = false;
                for (int i = 0; i < rows.Count; i++)
                {
                    var row        = rows[i];
                    var oldValue   = row.IsSelected;
                    row.IsSelected = isSelected;
                    if (row.IsSelected != oldValue)
                    {
                        anyChange = true;
                    }
                }
                if (!anyChange)
                {
                    dataPresenter.InvalidateView();
                }
            });

            return(new ScalarBinding <T>(onRefresh: v =>
            {
                var selectedCount = dataPresenter.SelectedRows.Count;
                if (selectedCount == 0)
                {
                    v.IsChecked = false;
                }
                else if (selectedCount == dataPresenter.Rows.Count - (dataPresenter.VirtualRow != null ? 1 : 0))
                {
                    v.IsChecked = true;
                }
                else
                {
                    v.IsChecked = null;
                }
            },
                                         onSetup: v =>
            {
                trigger.Attach(v);
            },
                                         onCleanup: v =>
            {
                trigger.Detach(v);
            }));
        }
 /// <summary>
 /// Binds <see cref="DataPresenter"/> to <see cref="GridHeader"/> to select/deselect all rows.
 /// </summary>
 /// <param name="dataPresenter">The DataPresenter.</param>
 /// <returns>The scalar binding object.</returns>
 public static ScalarBinding <GridHeader> BindToGridHeader(this DataPresenter dataPresenter)
 {
     return(ToSelectAll <GridHeader>(dataPresenter));
 }
示例#6
0
 void IService.Initialize(DataPresenter dataPresenter)
 {
     throw new NotSupportedException();
 }
示例#7
0
 public DataLoader(DataPresenter <T> dataPresenter)
 {
     Debug.Assert(dataPresenter != null);
     _dataPresenter = dataPresenter;
 }