示例#1
0
        /// <summary>
        /// Auto resize columns
        /// </summary>
        public static void AutoResizeColumns(ListView listView)
        {
            GridView gv = listView.View as GridView;

            if (gv != null)
            {
                foreach (GridViewColumn gvc in gv.Columns)
                {
                    // Set width to max value because actual width doesn't include margins
                    gvc.Width = double.MaxValue;

                    // Set it to NaN to remove white space
                    gvc.Width = double.NaN;
                }

                listView.UpdateLayout();
            }
        }
        public void AddListView(IEnumerable<Core.Fragment> ie, int colIndex)
        {
            if (mainGrid != null)
            {
                ListView lv = new ListView();
                lv.SetValue(Grid.ColumnProperty, colIndex);
                lv.SetValue(Grid.RowProperty, 1);

                ComboBox cmb = new ComboBox();
                cmb.SetValue(Grid.ColumnProperty, colIndex);
                cmb.SetValue(Grid.RowProperty, 0);
                cmb.SelectionChanged += Cmb_SelectionChanged;
                Associate(lv, cmb);

                mainGrid.Children.Add(cmb);
                mainGrid.Children.Add(lv);

                lv.ItemsSource = ie;
                listViews.Insert(colIndex, lv);
                RefreshMetaKeys(cmb, lv);
                lv.UpdateLayout();
            }
        }
示例#3
0
        private static void Data2Grid(string shapeName, DataTable dataTable)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Dictionary <string, UIElement> _objectsMap;
            UIElement obj;

            try
            {
                _objectsMap = (Dictionary <string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    InvokeHelper ret = new InvokeHelper(delegate
                    {
                        try
                        {
                            System.Windows.Controls.ListView shape = (System.Windows.Controls.ListView)obj;
                            GridView gridView = new GridView();
                            shape.View        = gridView;
                            shape.Items.Clear();

                            int i = 0;
                            foreach (DataColumn column in dataTable.Columns)
                            {
                                GridViewColumn Col          = new GridViewColumn();
                                GridViewColumnHeader header = new GridViewColumnHeader();
                                header.Content           = column.Caption;
                                header.Tag               = shape;
                                header.MouseDown        += new MouseButtonEventHandler(LDControls._ListViewHeaderMouseButtonEvent);
                                Col.Header               = header;
                                Col.Width                = Double.NaN;
                                Col.DisplayMemberBinding = new System.Windows.Data.Binding("col[" + i + "]");
                                i++;
                                gridView.Columns.Add(Col);
                            }

                            int columns = dataTable.Columns.Count;
                            foreach (DataRow row in dataTable.Rows)
                            {
                                DataGridRow dataGridRow = new DataGridRow();
                                dataGridRow.col         = new string[columns];
                                for (i = 0; i < columns; i++)
                                {
                                    dataGridRow.col[i] = row.ItemArray[i].ToString();
                                }
                                shape.Items.Add(dataGridRow);
                            }

                            shape.UpdateLayout();
                        }
                        catch (Exception ex)
                        {
                            Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        }
                    });
                    FastThread.Invoke(ret);
                }
                else
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
        }