void AddCheckBoxColumn() { CustomDataGridCheckBoxColumn checkBoxColumn = new CustomDataGridCheckBoxColumn(); checkBoxColumn.Header = "Отностится к документу"; Binding binding = new Binding("isConnected"); checkBoxColumn.Binding = binding; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; binding.Mode = BindingMode.TwoWay; checkBoxColumn.IsReadOnly = true; ConnectedDataGrid.Columns.Add(checkBoxColumn); }
public static DataGrid CreateDatagrid(int id = -1) { DataGrid table = new DataGrid(); table.AutoGenerateColumns = false; table.CanUserAddRows = false; table.CanUserDeleteRows = false; table.CanUserSortColumns = true; table.CanUserReorderColumns = false; table.SelectionMode = DataGridSelectionMode.Single; table.SelectionUnit = DataGridSelectionUnit.FullRow; /*table.LoadingRow += (object sender, DataGridRowEventArgs e) => * { * System.Diagnostics.Debug.WriteLine("over here"); * ((DocTable)e.Row.Item).number = e.Row.GetIndex() + 1; * };*/ Style style = (Style)Application.Current.MainWindow.TryFindResource("DataGridChangingColorStyle"); table.RowStyle = style; /*< DataTrigger Binding = "{Binding State}" Value = "State1" > * < Setter Property = "Background" Value = "Red" ></ Setter > * </ DataTrigger > * < DataTrigger Binding = "{Binding State}" Value = "State2" > * < Setter Property = "Background" Value = "Green" ></ Setter > * </ DataTrigger > */ table.MaxHeight = 500; table.IsReadOnly = true; /*table.LostFocus += (object sender, RoutedEventArgs e) => * { * table.UnselectAll(); * };*/ DataGridTextColumn textColumn = new DataGridTextColumn(); textColumn.Header = "#"; Binding binding = new Binding(); /* binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(DataGridRow), 1); * binding.Converter = new RowToIndexConverter();*/ textColumn.Binding = new Binding("number"); table.Columns.Add(textColumn); //< DataGridTextColumn Header = "#" Binding = "{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Converter={local:RowToIndexConverter}}" /> textColumn = new DataGridTextColumn(); textColumn.Header = "Название файла"; textColumn.Binding = new Binding("name"); table.Columns.Add(textColumn); textColumn = new DataGridTextColumn(); textColumn.Header = "Дата изменения"; binding = new Binding("date"); binding.StringFormat = "dd.MM.yy HH:mm:ss"; textColumn.Binding = binding; table.Columns.Add(textColumn); textColumn = new DataGridTextColumn(); textColumn.Header = "Пользователь"; textColumn.Binding = new Binding("username"); table.Columns.Add(textColumn); if (id != -1) { CustomDataGridCheckBoxColumn checkBoxColumn = new CustomDataGridCheckBoxColumn(); checkBoxColumn.Header = "Отностится к точке"; binding = new Binding("isConnected"); checkBoxColumn.Binding = binding; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; binding.Mode = BindingMode.TwoWay; checkBoxColumn.IsReadOnly = true; table.Columns.Add(checkBoxColumn); } return(table); }