|
1 | | -using Avalonia; |
2 | | -using Avalonia.Controls; |
| 1 | +using Avalonia.Controls; |
3 | 2 | using Avalonia.Interactivity; |
4 | 3 | using System.Collections.ObjectModel; |
5 | 4 |
|
6 | 5 | namespace AvRichTextBox; |
7 | 6 |
|
8 | | - |
9 | 7 | public partial class EditableTable : Grid, IEditableBlock |
10 | 8 | { |
11 | 9 | public bool IsEditable { get; set; } = true; |
12 | 10 |
|
13 | | - public static readonly StyledProperty<ObservableCollection<Border>> CellsProperty = AvaloniaProperty.Register<EditableTable, ObservableCollection<Border>>(nameof(Cells)); |
14 | | - public static readonly StyledProperty<ColumnDefinitions> ColDefsProperty = AvaloniaProperty.Register<EditableTable, ColumnDefinitions>(nameof(ColDefs)); |
15 | | - public static readonly StyledProperty<RowDefinitions> RowDefsProperty = AvaloniaProperty.Register<EditableTable, RowDefinitions>(nameof(RowDefs)); |
16 | | - |
17 | | - public ColumnDefinitions ColDefs |
| 11 | + public EditableTable() |
18 | 12 | { |
19 | | - get => GetValue(ColDefsProperty); |
20 | | - set { SetValue(ColDefsProperty, value); } |
| 13 | + Loaded += EditableTable_Loaded; |
21 | 14 | } |
22 | 15 |
|
23 | | - public RowDefinitions RowDefs |
24 | | - { |
25 | | - get => GetValue(RowDefsProperty); |
26 | | - set { SetValue(RowDefsProperty, value); } |
| 16 | + private void EditableTable_Loaded(object? sender, RoutedEventArgs e) |
| 17 | + { |
| 18 | + this.UpdateLayout(); |
27 | 19 | } |
28 | 20 |
|
29 | | - public ObservableCollection<Border> Cells |
| 21 | + public static readonly StyledProperty<ObservableCollection<EditableCell>> CellsProperty = AvaloniaProperty.Register<EditableTable, ObservableCollection<EditableCell>>(nameof(Cells), defaultValue: []); |
| 22 | + public ObservableCollection<EditableCell> Cells { get => GetValue(CellsProperty); set => SetValue(CellsProperty, value); } |
| 23 | + |
| 24 | + private void Cells_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) |
30 | 25 | { |
31 | | - get => GetValue(CellsProperty); |
32 | | - set => SetValue(CellsProperty, value); |
| 26 | + this.UpdateLayout(); |
33 | 27 | } |
34 | | - |
35 | | - //public EditableTable() |
36 | | - //{ |
37 | | - // this.Loaded += EditableTable_Loaded; |
38 | | - |
39 | | - //} |
40 | | - |
41 | | - //private void Cells_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) |
42 | | - //{ |
43 | | - // foreach (Border newCell in e.NewItems) |
44 | | - // this.Children.Add(newCell); |
45 | | - //} |
46 | | - |
47 | | - //private void ColDefs_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) |
48 | | - //{ |
49 | | - // foreach (ColumnDefinition cdef in e.NewItems) |
50 | | - // ColumnDefinitions.Add(cdef); |
51 | | - // foreach (ColumnDefinition cdef in e.OldItems) |
52 | | - // ColumnDefinitions.Remove(cdef); |
53 | | - |
54 | | - //} |
55 | | - |
56 | | - //private void RowDefs_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) |
57 | | - //{ |
58 | | - // foreach (RowDefinition rdef in e.NewItems) |
59 | | - // RowDefinitions.Add(rdef); |
60 | | - // foreach (RowDefinition rdef in e.OldItems) |
61 | | - // RowDefinitions.Remove(rdef); |
62 | | - |
63 | | - //} |
64 | | - |
65 | | - //private void EditableTable_Loaded(object? sender, RoutedEventArgs e) |
66 | | - //{ |
67 | | - // //ColDefs.CollectionChanged += ColDefs_CollectionChanged; |
68 | | - // //RowDefs.CollectionChanged += RowDefs_CollectionChanged; |
69 | | - // Cells.CollectionChanged += Cells_CollectionChanged; |
70 | | - |
71 | | - // RowDefinitions = RowDefs; |
72 | | - // ColumnDefinitions = ColDefs; |
73 | | - |
74 | | - // foreach (Border b in Cells) |
75 | | - // { |
76 | | - // this.Children.Add(b); |
77 | | - // //Debug.WriteLine(Grid.GetRow(b)); |
78 | | - // } |
79 | | - |
80 | | - // //Debug.WriteLine("cellcount=" + Cells.Count); |
81 | | - |
82 | | - // this.UpdateLayout(); |
83 | | - //} |
84 | | - |
| 28 | + |
85 | 29 | ////public string GetText => string.Join("", ((Table)this.DataContext).Inlines.ToList().ConvertAll(edinline => edinline.InlineText)); |
86 | 30 |
|
87 | | - |
88 | | - |
89 | 31 | } |
90 | 32 |
|
| 33 | + |
0 commit comments