private DataGridLength(double value, DataGridLengthUnitType type)
        {
            if (double.IsNaN(value))
            {
                throw DataGridError.DataGrid.ValueCannotBeSetToNAN("value");
            }
            if (double.IsInfinity(value))
            {
                throw DataGridError.DataGrid.ValueCannotBeSetToInfinity("value");
            }
            if (value < 0)
            {
                throw DataGridError.DataGrid.ValueMustBeGreaterThanOrEqualTo("value", "value", 0);
            }

            if (type != DataGridLengthUnitType.Auto &&
                type != DataGridLengthUnitType.SizeToCells &&
                type != DataGridLengthUnitType.SizeToHeader &&
                //
                type != DataGridLengthUnitType.Pixel)
            {
                throw DataGridError.DataGridLength.InvalidUnitType("type");
            }

            _unitValue = (type == DataGridLengthUnitType.Auto) ? DATAGRIDLENGTH_DefaultValue : value;
            _unitType  = type;
        }
 public ColumnInformation(DataGridColumn column)
 {
     Header = column.Header;
     if (!(column is DataGridTemplateColumn))
     {
         if (column is DataGridComboBoxColumn)
         {
             PropertyPath = column.SortMemberPath;
         }
         else
         {
             PropertyPath = ((Binding)((DataGridBoundColumn)column).Binding).Path.Path;
         }
     }
     else
     {
         PropertyPath = column.SortMemberPath;
     }
     WidthValue = column.Width.DisplayValue;
     WidthType = column.Width.UnitType;
     SortDirection = column.SortDirection;
     DisplayIndex = column.DisplayIndex;
     SortMemberPath = column.SortMemberPath;
     IsVisible = column.IsVisible;
 }
        private void loadPreferences()
        {
            userLimit.Text            = Properties.Settings.Default.prLimit.ToString();
            cbAutoApply.IsChecked     = Properties.Settings.Default.prAutoApply;
            checkAutoselect.IsChecked = Properties.Settings.Default.prAutoRefresh;
            if (Directory.Exists(Properties.Settings.Default.prWorkspace))
            {
                openFileDialog1.InitialDirectory = Properties.Settings.Default.prWorkspace;
                saveFileDialog1.InitialDirectory = Properties.Settings.Default.prWorkspace;
            }


            switch (Properties.Settings.Default.prFitMethod)
            {
            case 0:
                dataGridLengthUnit = DataGridLengthUnitType.Auto;
                break;

            case 1:
                dataGridLengthUnit = DataGridLengthUnitType.SizeToHeader;
                break;

            case 2:
                dataGridLengthUnit = DataGridLengthUnitType.SizeToCells;
                break;
            }
        }
 private void SetAllColumnWidths(DataGrid source, DataGridLengthUnitType lengthType, double minWidth)
 {
     for (int i = 0; i < source.Columns.Count; i++)
     {
         source.Columns[i].Width    = new DataGridLength(1.0, lengthType);
         source.Columns[i].MinWidth = minWidth;
     }
 }
Beispiel #5
0
        // Token: 0x06004921 RID: 18721 RVA: 0x0014B8A4 File Offset: 0x00149AA4
        private static DataGridLength ConvertFromString(string s, CultureInfo cultureInfo)
        {
            string text = s.Trim().ToLowerInvariant();

            for (int i = 0; i < 3; i++)
            {
                string b = DataGridLengthConverter._unitStrings[i];
                if (text == b)
                {
                    return(new DataGridLength(1.0, (DataGridLengthUnitType)i));
                }
            }
            double value = 0.0;
            DataGridLengthUnitType dataGridLengthUnitType = DataGridLengthUnitType.Pixel;
            int    length = text.Length;
            int    num    = 0;
            double num2   = 1.0;
            int    num3   = DataGridLengthConverter._unitStrings.Length;

            for (int j = 3; j < num3; j++)
            {
                string text2 = DataGridLengthConverter._unitStrings[j];
                if (text.EndsWith(text2, StringComparison.Ordinal))
                {
                    num = text2.Length;
                    dataGridLengthUnitType = (DataGridLengthUnitType)j;
                    break;
                }
            }
            if (num == 0)
            {
                num3 = DataGridLengthConverter._nonStandardUnitStrings.Length;
                for (int k = 0; k < num3; k++)
                {
                    string text3 = DataGridLengthConverter._nonStandardUnitStrings[k];
                    if (text.EndsWith(text3, StringComparison.Ordinal))
                    {
                        num  = text3.Length;
                        num2 = DataGridLengthConverter._pixelUnitFactors[k];
                        break;
                    }
                }
            }
            if (length == num)
            {
                if (dataGridLengthUnitType == DataGridLengthUnitType.Star)
                {
                    value = 1.0;
                }
            }
            else
            {
                string value2 = text.Substring(0, length - num);
                value = Convert.ToDouble(value2, cultureInfo) * num2;
            }
            return(new DataGridLength(value, dataGridLengthUnitType));
        }
        private static List <ColumnInfo> LoadColumns(XmlElement parent)
        {
            List <ColumnInfo> CInfo = new List <ColumnInfo>();

            foreach (XmlElement xNode in parent)
            {
                string                 ColumnHeader = String.Empty;
                Visibility             visibility   = Visibility.Visible;
                int                    DisplayIndex = 0;
                double                 WidthValue   = 40.0;
                DataGridLengthUnitType WidthType    = DataGridLengthUnitType.Auto;
                Style                  ColStyle     = new Style();
                string                 StringFormat = null;
                foreach (XmlNode childNode in xNode.ChildNodes)
                {
                    switch (childNode.Name)
                    {
                    case "ColumnHeader":
                        ColumnHeader = childNode.InnerText;
                        break;

                    case "Visibility":
                        Enum.TryParse(childNode.InnerText, out visibility);
                        break;

                    case "DisplayIndex":
                        Int32.TryParse(childNode.InnerText, out DisplayIndex);
                        break;

                    case "WidthValue":
                        Double.TryParse(childNode.InnerText, out WidthValue);
                        break;

                    case "WidthType":
                        Enum.TryParse(childNode.InnerText, out WidthType);
                        break;

                    case "Style":
                        ColStyle = LoadStyle(childNode);
                        break;

                    case "StringFormat":
                        StringFormat = childNode.InnerText;
                        break;
                    }
                }
                if (ColumnHeader == String.Empty)
                {
                    break;
                }
                ColumnInfo column = new ColumnInfo(visibility, DisplayIndex, WidthValue, WidthType,
                                                   ColumnHeader, ColStyle, StringFormat);
                CInfo.Add(column);
            }

            return(CInfo);
        }
Beispiel #7
0
 public ColumnInfo(DataGridColumn column)
 {
     Header        = column.Header;
     PropertyPath  = ((Binding)((DataGridBoundColumn)column).Binding).Path.Path;
     WidthValue    = column.Width.DisplayValue;
     WidthType     = column.Width.UnitType;
     SortDirection = column.SortDirection;
     DisplayIndex  = column.DisplayIndex;
 }
Beispiel #8
0
        public DataGridLengthUnitType WidthType;     // Width type (Pixel, Star, Auto...)

        public ColumnInfo(DataGridColumn column)
        {
            Header        = column.Header;
            PropertyPath  = column.SortMemberPath;
            WidthValue    = column.Width.DisplayValue;
            WidthType     = column.Width.UnitType;
            Visibility    = column.Visibility;
            SortDirection = column.SortDirection;
            DisplayIndex  = column.DisplayIndex;
        }
Beispiel #9
0
    public static void CreateColumn(DataGrid datagrid, string header, int width = 1, DataGridLengthUnitType type = DataGridLengthUnitType.Star)
    {
        var c = new DataGridTextColumn()
        {
            Header  = header,
            Binding = new Binding(header),
            Width   = new DataGridLength(width, type)
        };

        datagrid.Columns.Add(c);
    }
Beispiel #10
0
        public DataGridTextColumn AddNewTextColumn(string header, string binding,
                                                   bool isVisible                   = false, BindingMode mode = BindingMode.OneWay,
                                                   bool notifyOnTargetUpdated       = true, double width      = 1.0,
                                                   DataGridLengthUnitType widthType = DataGridLengthUnitType.Star)
        {
            var textColumn = DataGridTextColumn(header, binding, isVisible,
                                                mode, notifyOnTargetUpdated, width, widthType);

            Columns.Add(textColumn);
            return(textColumn);
        }
Beispiel #11
0
 public ColumnInfo(Visibility vis, int dispIdx, double widthVal, DataGridLengthUnitType widthT,
                   string columnHeader, Style colStyle, string colStringFormat)
 {
     WidthValue   = widthVal;
     WidthType    = widthT;
     DisplayIndex = dispIdx;
     Visibility   = vis;
     ColumnHeader = columnHeader;
     ColStyle     = colStyle;
     StringFormat = colStringFormat;
 }
 public static void LoadDataGridDimensions(this DataGrid grid, string dimensionPrefix)
 {
     for (int i = 0; i < grid.Columns.Count; i++)
     {
         string dimensionName = $"{dimensionPrefix}_Col{i}";
         var    colDimensions = CMDataProvider.DataStore.Value.CMDimensionInfos.Value.Get_ForName(dimensionName);
         if (colDimensions != null)
         {
             // Top stores the DataGridLengthUnitType
             DataGridLengthUnitType glut = (DataGridLengthUnitType)colDimensions.Top;
             grid.Columns[i].Width = new DataGridLength(colDimensions.Width, glut);
         }
     }
 }
        //{
        //    if (dg.ColumnHeaderStyle == null)
        //        dg.ColumnHeaderStyle = new Style(typeof(DataGridColumnHeader));

        //    CreateColumnHeaderStyle(dg, colWidthType);
        //}


        private static Style CreateColumnHeaderStyle(DataGrid dg, DataGridLengthUnitType colWidthType)
        {
            var colHdrStyle = new Style(typeof(DataGridColumnHeader), dg.ColumnHeaderStyle);
            var ctxMenuKey  = $"ctxMenu_{Guid.NewGuid().ToString("N")}";
            var ctxMenu     = CreateContextMenu(dg, colWidthType);

            colHdrStyle.Resources.Add(ctxMenuKey, ctxMenu);

            colHdrStyle.Setters.Add(ContextMenuSetter(ctxMenu));

            colHdrStyle.Setters.Add(HorizontalAlignmentSetter);
            //colHdrStyle.Setters.Add(FontWeightSetter);
            colHdrStyle.Setters.Add(FontStyleSetter);
            colHdrStyle.Setters.Add(ForegroundSetter);
            colHdrStyle.Setters.Add(PaddingSetter);

            return(colHdrStyle);
        }
        private static ContextMenu CreateContextMenu(DataGrid dg, DataGridLengthUnitType colWidthType)
        {
            var cm = new ContextMenu();

            foreach (var col in dg.Columns)
            {
                var mnu = new MenuItem();
                mnu.Header      = col.Header;
                mnu.IsCheckable = true;
                mnu.IsChecked   = col.Visibility == Visibility.Visible;
                mnu.Click      += (s, e) => col.Visibility = mnu.IsChecked
                            ? Visibility.Visible : Visibility.Collapsed;
                cm.Items.Add(mnu);
                col.Width = new DataGridLength(0, colWidthType);
            }

            return(cm);
        }
Beispiel #15
0
        private void SetLengthValue()
        {
            DataGridLengthUnitType unitType = (DataGridLengthUnitType)_comboBox.SelectedItem;

            switch (unitType)
            {
            case DataGridLengthUnitType.Auto:
                // To get around grow only in the designer, set the width to a small value
                this.SetValueNoCallback(DataGridLengthEditorGrid.ValueProperty, new SSWC.DataGridLength(1));
                this.Value = SSWC.DataGridLength.Auto;
                break;

            case DataGridLengthUnitType.SizeToCells:
                // To get around grow only in the designer, set the width to a small value
                this.SetValueNoCallback(DataGridLengthEditorGrid.ValueProperty, new SSWC.DataGridLength(1));
                this.Value = SSWC.DataGridLength.SizeToCells;
                break;

            case DataGridLengthUnitType.SizeToHeader:
                // To get around grow only in the designer, set the width to a small value
                this.SetValueNoCallback(DataGridLengthEditorGrid.ValueProperty, new SSWC.DataGridLength(1));
                this.Value = SSWC.DataGridLength.SizeToHeader;
                break;

            default:
                // Treat it as a Pixel length
                double pixels;
                if (double.TryParse(_textBox.Text, out pixels))
                {
                    // Store the last good pixel value
                    _lastValidPixelWidth = pixels;
                    this.Value           = new SSWC.DataGridLength(pixels);
                }
                else
                {
                    // The user entered something bad so revert to the last good value
                    _textBox.Text = _lastValidPixelWidth.ToString(CultureInfo.InvariantCulture);
                    // The Text binding does not update the Value in this case so set it explicitly
                    this.Value = new SSWC.DataGridLength(_lastValidPixelWidth);
                }
                break;
            }
        }
Beispiel #16
0
        /// <summary>
        ///     Initializes to a specified value and unit.
        /// </summary>
        /// <param name="value">The value to hold.</param>
        /// <param name="type">The unit of <c>value</c>.</param>
        /// <param name="desiredValue"></param>
        /// <param name="displayValue"></param>
        /// <remarks>
        ///     <c>value</c> is ignored unless <c>type</c> is
        ///     <c>DataGridLengthUnitType.Pixel</c> or
        ///     <c>DataGridLengthUnitType.Star</c>
        /// </remarks>
        /// <exception cref="ArgumentException">
        ///     If <c>value</c> parameter is <c>double.NaN</c>
        ///     or <c>value</c> parameter is <c>double.NegativeInfinity</c>
        ///     or <c>value</c> parameter is <c>double.PositiveInfinity</c>.
        /// </exception>
        public DataGridLength(double value, DataGridLengthUnitType type, double desiredValue, double displayValue)
        {
            if (DoubleUtil.IsNaN(value) || Double.IsInfinity(value))
            {
                throw new ArgumentException(
                          SR.Get(SRID.DataGridLength_Infinity),
                          "value");
                //  value = 100;
            }

            if (type != DataGridLengthUnitType.Auto &&
                type != DataGridLengthUnitType.Pixel &&
                type != DataGridLengthUnitType.Star &&
                type != DataGridLengthUnitType.SizeToCells &&
                type != DataGridLengthUnitType.SizeToHeader)
            {
                throw new ArgumentException(
                          SR.Get(SRID.DataGridLength_InvalidType),
                          "type");
            }

            if (Double.IsInfinity(desiredValue))
            {
                throw new ArgumentException(
                          SR.Get(SRID.DataGridLength_Infinity),
                          "desiredValue");
            }

            if (Double.IsInfinity(displayValue))
            {
                throw new ArgumentException(
                          SR.Get(SRID.DataGridLength_Infinity),
                          "displayValue");
            }

            _unitValue = (type == DataGridLengthUnitType.Auto) ? AutoValue : value;
            _unitType  = type;

            _desiredValue = desiredValue;
            _displayValue = displayValue;
        }
 /// <summary>Initializes a new instance of the <see cref="T:System.Windows.Controls.DataGridLength" /> class with the specified value, unit, desired value, and display value.</summary>
 /// <param name="value">The requested size of the element.</param>
 /// <param name="type">The type that is used to determine how the size of the element is calculated.</param>
 /// <param name="desiredValue">The calculated size needed for the element.</param>
 /// <param name="displayValue">The allocated size for the element.</param>
 /// <exception cref="T:System.ArgumentException">
 ///         <paramref name="value" /> is <see cref="F:System.Double.NaN" />, <see cref="F:System.Double.NegativeInfinity" />, or <see cref="F:System.Double.PositiveInfinity" />.-or-
 ///         <paramref name="type" /> is not <see cref="F:System.Windows.Controls.DataGridLengthUnitType.Auto" />, <see cref="F:System.Windows.Controls.DataGridLengthUnitType.Pixel" />, <see cref="F:System.Windows.Controls.DataGridLengthUnitType.Star" />, <see cref="F:System.Windows.Controls.DataGridLengthUnitType.SizeToCells" />, or <see cref="F:System.Windows.Controls.DataGridLengthUnitType.SizeToHeader" />.-or-
 ///         <paramref name="desiredValue" /> is <see cref="F:System.Double.NegativeInfinity" /> or <see cref="F:System.Double.PositiveInfinity" />.-or-
 ///         <paramref name="displayValue" /> is <see cref="F:System.Double.NegativeInfinity" /> or <see cref="F:System.Double.PositiveInfinity" />.</exception>
 // Token: 0x06004907 RID: 18695 RVA: 0x0014B360 File Offset: 0x00149560
 public DataGridLength(double value, DataGridLengthUnitType type, double desiredValue, double displayValue)
 {
     if (DoubleUtil.IsNaN(value) || double.IsInfinity(value))
     {
         throw new ArgumentException(SR.Get("DataGridLength_Infinity"), "value");
     }
     if (type != DataGridLengthUnitType.Auto && type != DataGridLengthUnitType.Pixel && type != DataGridLengthUnitType.Star && type != DataGridLengthUnitType.SizeToCells && type != DataGridLengthUnitType.SizeToHeader)
     {
         throw new ArgumentException(SR.Get("DataGridLength_InvalidType"), "type");
     }
     if (double.IsInfinity(desiredValue))
     {
         throw new ArgumentException(SR.Get("DataGridLength_Infinity"), "desiredValue");
     }
     if (double.IsInfinity(displayValue))
     {
         throw new ArgumentException(SR.Get("DataGridLength_Infinity"), "displayValue");
     }
     this._unitValue    = ((type == DataGridLengthUnitType.Auto) ? 1.0 : value);
     this._unitType     = type;
     this._desiredValue = desiredValue;
     this._displayValue = displayValue;
 }
Beispiel #18
0
 /// <summary>
 ///     Helper method which coerces the DesiredValue or DisplayValue
 ///     of the width.
 /// </summary>
 private static double CoerceDesiredOrDisplayWidthValue(double widthValue, double memberValue, DataGridLengthUnitType type)
 {
     if (DoubleUtil.IsNaN(memberValue))
     {
         if (type == DataGridLengthUnitType.Pixel)
         {
             memberValue = widthValue;
         }
         else if (type == DataGridLengthUnitType.Auto ||
             type == DataGridLengthUnitType.SizeToCells ||
             type == DataGridLengthUnitType.SizeToHeader)
         {
             memberValue = 0d;
         }
     }
     return memberValue;
 }
Beispiel #19
0
 /// <summary>
 ///     Initializes to a specified value and unit.
 /// </summary>
 /// <param name="value">The value to hold.</param>
 /// <param name="type">The unit of <c>value</c>.</param>
 /// <remarks>
 ///     <c>value</c> is ignored unless <c>type</c> is
 ///     <c>DataGridLengthUnitType.Pixel</c> or
 ///     <c>DataGridLengthUnitType.Star</c>
 /// </remarks>
 /// <exception cref="ArgumentException">
 ///     If <c>value</c> parameter is <c>double.NaN</c>
 ///     or <c>value</c> parameter is <c>double.NegativeInfinity</c>
 ///     or <c>value</c> parameter is <c>double.PositiveInfinity</c>.
 /// </exception>
 public DataGridLength(double value, DataGridLengthUnitType type)
     : this(value, type, (type == DataGridLengthUnitType.Pixel ? value : Double.NaN), (type == DataGridLengthUnitType.Pixel ? value : Double.NaN))
 {
 }
Beispiel #20
0
 private static DataGridTextColumn DataGridTextColumn(string header, string binding, bool isVisible, BindingMode mode,
                                                      bool notifyOnTargetUpdated, double width, DataGridLengthUnitType widthType)
 {
     return(new DataGridTextColumn
     {
         Header = header,
         Width = new DataGridLength(width, widthType),
         Visibility = isVisible ? Visibility.Visible : Visibility.Hidden,
         Binding = new Binding(binding)
         {
             Mode = mode,
             NotifyOnTargetUpdated = notifyOnTargetUpdated,
         },
         IsReadOnly = false
     });
 }
 /// <summary>Initializes a new instance of the <see cref="T:System.Windows.Controls.DataGridLength" /> class with a specified value and unit.</summary>
 /// <param name="value">The requested size of the element.</param>
 /// <param name="type">The type that is used to determine how the size of the element is calculated.</param>
 /// <exception cref="T:System.ArgumentException">
 ///         <paramref name="value" /> is <see cref="F:System.Double.NaN" />, <see cref="F:System.Double.NegativeInfinity" />, or <see cref="F:System.Double.PositiveInfinity" />.-or-
 ///         <paramref name="type" /> is not <see cref="F:System.Windows.Controls.DataGridLengthUnitType.Auto" />, <see cref="F:System.Windows.Controls.DataGridLengthUnitType.Pixel" />, <see cref="F:System.Windows.Controls.DataGridLengthUnitType.Star" />, <see cref="F:System.Windows.Controls.DataGridLengthUnitType.SizeToCells" />, or <see cref="F:System.Windows.Controls.DataGridLengthUnitType.SizeToHeader" />.</exception>
 // Token: 0x06004906 RID: 18694 RVA: 0x0014B335 File Offset: 0x00149535
 public DataGridLength(double value, DataGridLengthUnitType type)
 {
     this = new DataGridLength(value, type, (type == DataGridLengthUnitType.Pixel) ? value : double.NaN, (type == DataGridLengthUnitType.Pixel) ? value : double.NaN);
 }
        /// <summary>
        ///     Parses a DataGridLength from a string given the CultureInfo.
        /// </summary>
        /// <param name="s">String to parse from.</param>
        /// <param name="cultureInfo">Culture Info.</param>
        /// <returns>Newly created DataGridLength instance.</returns>
        /// <remarks>
        /// Formats:
        /// "[value][unit]"
        ///     [value] is a double
        ///     [unit] is a string in DataGridLength._unitTypes connected to a DataGridLengthUnitType
        /// "[value]"
        ///     As above, but the DataGridLengthUnitType is assumed to be DataGridLengthUnitType.Pixel
        /// "[unit]"
        ///     As above, but the value is assumed to be 1.0
        ///     This is only acceptable for a subset of DataGridLengthUnitType: Auto
        /// </remarks>
        private static DataGridLength ConvertFromString(string s, CultureInfo cultureInfo)
        {
            string goodString = s.Trim().ToLowerInvariant();

            // Check if the string matches any of the descriptive unit types.
            // In these cases, there is no need to parse a value.
            for (int i = 0; i < NumDescriptiveUnits; i++)
            {
                string unitString = _unitStrings[i];
                if (goodString == unitString)
                {
                    return(new DataGridLength(1.0, (DataGridLengthUnitType)i));
                }
            }

            double value = 0.0;
            DataGridLengthUnitType unit = DataGridLengthUnitType.Pixel;
            int    strLen     = goodString.Length;
            int    strLenUnit = 0;
            double unitFactor = 1.0;

            // Check if the string contains a non-descriptive unit at the end.
            int numUnitStrings = _unitStrings.Length;

            for (int i = NumDescriptiveUnits; i < numUnitStrings; i++)
            {
                string unitString = _unitStrings[i];

                // Note: This is NOT a culture specific comparison.
                // This is by design: we want the same unit string table to work across all cultures.
                if (goodString.EndsWith(unitString, StringComparison.Ordinal))
                {
                    strLenUnit = unitString.Length;
                    unit       = (DataGridLengthUnitType)i;
                    break;
                }
            }

            // Couldn't match a standard unit type, try a non-standard unit type.
            if (strLenUnit == 0)
            {
                numUnitStrings = _nonStandardUnitStrings.Length;
                for (int i = 0; i < numUnitStrings; i++)
                {
                    string unitString = _nonStandardUnitStrings[i];

                    // Note: This is NOT a culture specific comparison.
                    // This is by design: we want the same unit string table to work across all cultures.
                    if (goodString.EndsWith(unitString, StringComparison.Ordinal))
                    {
                        strLenUnit = unitString.Length;
                        unitFactor = _pixelUnitFactors[i];
                        break;
                    }
                }
            }

            // Check if there is a numerical value to parse
            if (strLen == strLenUnit)
            {
                // There is no numerical value to parse
                if (unit == DataGridLengthUnitType.Star)
                {
                    // Star's value defaults to 1. Anyone else would be 0.
                    value = 1.0;
                }
            }
            else
            {
                // Parse a numerical value
                Debug.Assert(
                    (unit == DataGridLengthUnitType.Pixel) || DoubleUtil.AreClose(unitFactor, 1.0),
                    "unitFactor should not be other than 1.0 unless the unit type is Pixel.");

                string valueString = goodString.Substring(0, strLen - strLenUnit);
                value = Convert.ToDouble(valueString, cultureInfo) * unitFactor;
            }

            return(new DataGridLength(value, unit));
        }
        private static Style CreateColumnHeaderStyle(DataGrid dg, Style columnHeaderStyle, DataGridLengthUnitType colWidthType)
        {
            var newStyle   = new Style(typeof(DataGridColumnHeader), columnHeaderStyle);
            var ctxMenuKey = $"ctxMenu_{Guid.NewGuid().ToString("N")}";
            var ctxMenu    = CreateContextMenu(dg, colWidthType);

            newStyle.Resources.Add(ctxMenuKey, ctxMenu);
            newStyle.Setters.Add(ContextMenuSetter(ctxMenu));
            return(newStyle);
        }
Beispiel #24
0
 // Exceptions:
 //   System.ArgumentException:
 //     value is System.Double.NaN, System.Double.NegativeInfinity, or System.Double.PositiveInfinity.-or-type
 //     is not System.Windows.Controls.DataGridLengthUnitType.Auto, System.Windows.Controls.DataGridLengthUnitType.Pixel,
 //     System.Windows.Controls.DataGridLengthUnitType.Star, System.Windows.Controls.DataGridLengthUnitType.SizeToCells,
 //     or System.Windows.Controls.DataGridLengthUnitType.SizeToHeader.
 /// <summary>
 /// Initializes a new instance of the System.Windows.Controls.DataGridLength
 /// class with a specified value and unit.
 /// </summary>
 /// <param name="value">The requested size of the element.</param>
 /// <param name="type">The type that is used to determine how the size of the element is calculated.</param>
 public DataGridLength(double value, DataGridLengthUnitType type)
 {
     _value = (type == DataGridLengthUnitType.Auto ? 0.0 : value);
     _type  = type;
 }
        /// <summary>
        /// Attempts to resize the column's width to the desired DisplayValue, but limits the final size
        /// to the column's minimum and maximum values.  If star sizing is being used, then the column
        /// can only decrease in size by the amount that the columns after it can increase in size.
        /// Likewise, the column can only increase in size if other columns can spare the width.
        /// </summary>
        /// <param name="value">The new Value.</param>
        /// <param name="unitType">The new UnitType.</param>
        /// <param name="desiredValue">The new DesiredValue.</param>
        /// <param name="displayValue">The new DisplayValue.</param>
        /// <param name="userInitiated">Whether or not this resize was initiated by a user action.</param>
        internal void Resize(double value, DataGridLengthUnitType unitType, double desiredValue, double displayValue, bool userInitiated)
        {
            Debug.Assert(this.OwningGrid != null);

            double newValue                    = value;
            double newDesiredValue             = desiredValue;
            double newDisplayValue             = Math.Max(this.ActualMinWidth, Math.Min(this.ActualMaxWidth, displayValue));
            DataGridLengthUnitType newUnitType = unitType;

            int    starColumnsCount  = 0;
            double totalDisplayWidth = 0;

            foreach (DataGridColumn column in this.OwningGrid.ColumnsInternal.GetVisibleColumns())
            {
                column.EnsureWidth();
                totalDisplayWidth += column.ActualWidth;
                starColumnsCount  += (column != this && column.Width.IsStar) ? 1 : 0;
            }
            bool hasInfiniteAvailableWidth = !this.OwningGrid.RowsPresenterAvailableSize.HasValue || double.IsPositiveInfinity(this.OwningGrid.RowsPresenterAvailableSize.Value.Width);

            // If we're using star sizing, we can only resize the column as much as the columns to the
            // right will allow (i.e. until they hit their max or min widths).
            if (!hasInfiniteAvailableWidth && (starColumnsCount > 0 || (unitType == DataGridLengthUnitType.Star && this.Width.IsStar && userInitiated)))
            {
                double limitedDisplayValue = this.Width.DisplayValue;
                double availableIncrease   = Math.Max(0, this.OwningGrid.CellsWidth - totalDisplayWidth);
                double desiredChange       = newDisplayValue - this.Width.DisplayValue;
                if (desiredChange > availableIncrease)
                {
                    // The desired change is greater than the amount of available space,
                    // so we need to decrease the widths of columns to the right to make room.
                    desiredChange -= availableIncrease;
                    double actualChange = desiredChange + this.OwningGrid.DecreaseColumnWidths(this.DisplayIndex + 1, -desiredChange, userInitiated);
                    limitedDisplayValue += availableIncrease + actualChange;
                }
                else if (desiredChange > 0)
                {
                    // The desired change is positive but less than the amount of available space,
                    // so there's no need to decrease the widths of columns to the right.
                    limitedDisplayValue += desiredChange;
                }
                else
                {
                    // The desired change is negative, so we need to increase the widths of columns to the right.
                    limitedDisplayValue += desiredChange + this.OwningGrid.IncreaseColumnWidths(this.DisplayIndex + 1, -desiredChange, userInitiated);
                }
                if (this.ActualCanUserResize || (this.Width.IsStar && !userInitiated))
                {
                    newDisplayValue = limitedDisplayValue;
                }
            }

            if (userInitiated)
            {
                newDesiredValue = newDisplayValue;
                if (!this.Width.IsStar)
                {
                    this.InheritsWidth = false;
                    newValue           = newDisplayValue;
                    newUnitType        = DataGridLengthUnitType.Pixel;
                }
                else if (starColumnsCount > 0 && !hasInfiniteAvailableWidth)
                {
                    // Recalculate star weight of this column based on the new desired value
                    this.InheritsWidth = false;
                    newValue           = (this.Width.Value * newDisplayValue) / this.ActualWidth;
                }
            }

            DataGridLength oldWidth = this.Width;

            SetWidthInternalNoCallback(new DataGridLength(Math.Min(double.MaxValue, newValue), newUnitType, newDesiredValue, newDisplayValue));
            if (this.Width != oldWidth)
            {
                this.OwningGrid.OnColumnWidthChanged(this);
            }
        }
Beispiel #26
0
        public static DataGridTemplateColumn GenTemplateColumnAllText(string strHeader, string strHeaderElement, string strCellElement, double nWidth, DataGridLengthUnitType lenType)
        {
            DataGridTemplateColumn item = new DataGridTemplateColumn();

            item.Header         = strHeader;
            item.Width          = new DataGridLength(nWidth, lenType);
            item.CanUserReorder = false;
            item.CanUserResize  = false;
            item.CanUserSort    = false;
            StringBuilder sb = new StringBuilder();

            sb.Append("<DataTemplate");
            sb.Append(" xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'");
            sb.Append(" xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>");
            sb.Append(strCellElement);
            sb.Append("</DataTemplate>");

            StringReader  reader    = new StringReader(sb.ToString());
            XmlTextReader xmlReader = new XmlTextReader(reader);

            item.CellTemplate = (DataTemplate)XamlReader.Load(xmlReader);

            sb.Clear();
            sb.Append("<DataTemplate");
            sb.Append(" xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'");
            sb.Append(" xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>");
            sb.Append(strHeaderElement);
            sb.Append("</DataTemplate>");

            reader              = new StringReader(sb.ToString());
            xmlReader           = new XmlTextReader(reader);
            item.HeaderTemplate = (DataTemplate)XamlReader.Load(xmlReader);
            return(item);
        }
Beispiel #27
0
 // Exceptions:
 //   System.ArgumentException:
 //     pixels is System.Double.NaN, System.Double.NegativeInfinity, or System.Double.PositiveInfinity.
 /// <summary>
 /// Initializes a new instance of the System.Windows.Controls.DataGridLength
 /// class with an absolute value in pixels.
 /// </summary>
 /// <param name="pixels">The absolute pixel value (96 pixels-per-inch) to initialize the length to.</param>
 public DataGridLength(double pixels)
 {
     _value = pixels;
     _type  = DataGridLengthUnitType.Pixel;
 }
 public DataGridLength(double value, DataGridLengthUnitType type, double desiredValue, double displayValue)
 {
     Contract.Ensures(!double.IsInfinity(desiredValue));
     Contract.Ensures(!double.IsInfinity(displayValue));
     Contract.Ensures(!double.IsInfinity(value));
 }
 public DataGridLength(double value, DataGridLengthUnitType type)
 {
     Contract.Ensures(!double.IsInfinity(value));
 }
        /// <summary>
        /// Attempts to resize the column's width to the desired DisplayValue, but limits the final size
        /// to the column's minimum and maximum values.  If star sizing is being used, then the column
        /// can only decrease in size by the amount that the columns after it can increase in size.
        /// Likewise, the column can only increase in size if other columns can spare the width.
        /// </summary>
        /// <param name="value">The new Value.</param>
        /// <param name="unitType">The new UnitType.</param>
        /// <param name="desiredValue">The new DesiredValue.</param>
        /// <param name="displayValue">The new DisplayValue.</param>
        /// <param name="userInitiated">Whether or not this resize was initiated by a user action.</param>
        internal void Resize(double value, DataGridLengthUnitType unitType, double desiredValue, double displayValue, bool userInitiated)
        {
            Debug.Assert(this.OwningGrid != null);

            double newValue = value;
            double newDesiredValue = desiredValue;
            double newDisplayValue = Math.Max(this.ActualMinWidth, Math.Min(this.ActualMaxWidth, displayValue));
            DataGridLengthUnitType newUnitType = unitType;

            int starColumnsCount = 0;
            double totalDisplayWidth = 0;
            foreach (DataGridColumn column in this.OwningGrid.ColumnsInternal.GetVisibleColumns())
            {
                column.EnsureWidth();
                totalDisplayWidth += column.ActualWidth;
                starColumnsCount += (column != this && column.Width.IsStar) ? 1 : 0;
            }
            bool hasInfiniteAvailableWidth = !this.OwningGrid.RowsPresenterAvailableSize.HasValue || double.IsPositiveInfinity(this.OwningGrid.RowsPresenterAvailableSize.Value.Width);

            // If we're using star sizing, we can only resize the column as much as the columns to the
            // right will allow (i.e. until they hit their max or min widths).
            if (!hasInfiniteAvailableWidth && (starColumnsCount > 0 || (unitType == DataGridLengthUnitType.Star && this.Width.IsStar && userInitiated)))
            {
                double limitedDisplayValue = this.Width.DisplayValue;
                double availableIncrease = Math.Max(0, this.OwningGrid.CellsWidth - totalDisplayWidth);
                double desiredChange = newDisplayValue - this.Width.DisplayValue;
                if (desiredChange > availableIncrease)
                {
                    // The desired change is greater than the amount of available space,
                    // so we need to decrease the widths of columns to the right to make room.
                    desiredChange -= availableIncrease;
                    double actualChange = desiredChange + this.OwningGrid.DecreaseColumnWidths(this.DisplayIndex + 1, -desiredChange, userInitiated);
                    limitedDisplayValue += availableIncrease + actualChange;
                }
                else if (desiredChange > 0)
                {
                    // The desired change is positive but less than the amount of available space,
                    // so there's no need to decrease the widths of columns to the right.
                    limitedDisplayValue += desiredChange;
                }
                else
                {
                    // The desired change is negative, so we need to increase the widths of columns to the right.
                    limitedDisplayValue += desiredChange + this.OwningGrid.IncreaseColumnWidths(this.DisplayIndex + 1, -desiredChange, userInitiated);
                }
                if (this.ActualCanUserResize || (this.Width.IsStar && !userInitiated))
                {
                    newDisplayValue = limitedDisplayValue;
                }
            }

            if (userInitiated)
            {
                newDesiredValue = newDisplayValue;
                if (!this.Width.IsStar)
                {
                    this.InheritsWidth = false;
                    newValue = newDisplayValue;
                    newUnitType = DataGridLengthUnitType.Pixel;
                }
                else if (starColumnsCount > 0 && !hasInfiniteAvailableWidth)
                {
                    // Recalculate star weight of this column based on the new desired value
                    this.InheritsWidth = false;
                    newValue = (this.Width.Value * newDisplayValue) / this.ActualWidth;
                }
            }

            DataGridLength oldWidth = this.Width;
            SetWidthInternalNoCallback(new DataGridLength(Math.Min(double.MaxValue, newValue), newUnitType, newDesiredValue, newDisplayValue));
            if (this.Width != oldWidth)
            {
                this.OwningGrid.OnColumnWidthChanged(this);
            }
        }
 public ColumnInfo(DataGridColumn column) {
     Header = column.Header;
     PropertyPath = ((Binding) ((DataGridBoundColumn) column).Binding).Path.Path;
     WidthValue = column.Width.DisplayValue;
     WidthType = column.Width.UnitType;
     SortDirection = column.SortDirection;
     DisplayIndex = column.DisplayIndex;
 }
 public static void EnableToggledColumns(this DataGrid dg, DataGridLengthUnitType colWidthType = DataGridLengthUnitType.SizeToCells)
 => dg.ColumnHeaderStyle = CreateColumnHeaderStyle(dg, colWidthType);