Проблема в том, что холст не «сохраняет» свою высоту при запуске функции Compute_Change_height_of_ressource. >
У меня есть этот класс
Код: Выделить всё
public partial class RessourceTreeViewItem : TreeViewItem {
public int RG_ID { get; set; }
public double height_of_ressource { get; set; }
StackPanel taskPanel { get; set; }
Label taskLabel { get; set; }
public String RGLabeltxt { get; set; }
public Canvas backgroundcanvas { get; set; }
public ScrollViewer scrollViewer { get; set; }
public DateTime startdatetime { get; set; }
public DockPanel panel { get; set; }
public RessourceTreeViewItem(int RG_ID, double dots_per_minute, DateTime startdatetime, DateTime enddatetime, String RGLabeltxt, double height_of_ressource)
{
this.RGLabeltxt = RGLabeltxt;
this.RG_ID = RG_ID;
this.startdatetime = startdatetime;
this.height_of_ressource = height_of_ressource;
this.panel = new DockPanel();
this.panel.HorizontalAlignment = HorizontalAlignment.Left;
this.taskLabel = new Label() {
Content = this.RGLabeltxt
};
this.taskLabel.Width = 40;
this.Margin = new Thickness(-40, 0, 0, 0);
this.backgroundcanvas = new Canvas();
this.backgroundcanvas.Height = this.height_of_ressource;
this.scrollViewer = new ScrollViewer();
this.scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
this.scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
this.scrollViewer.Content = this.backgroundcanvas;
// Add the task label and the scroll viewer to the task panel
this.panel.Children.Add(taskLabel);
this.panel.Children.Add(this.scrollViewer);
this.Header = this.panel;
}
public void Compute_Change_height_of_ressource(double height_of_ressource)
{
foreach (TimeLineItem item in this.backgroundcanvas.Children)
{
item.Compute_Change_height_of_ressource(height_of_ressource);
}
this.height_of_ressource = height_of_ressource;
this.panel.Height = height_of_ressource;
this.scrollViewer.Height = height_of_ressource;
this.backgroundcanvas.Height = height_of_ressource;
}
Все остальные атрибуты были изменены.
В визуальном дереве есть ScrollContentPresenter, родительский элемент backgroundcanvas, который имеет старую высоту – как ее изменить?РЕДАКТИРОВАТЬ
Хорошо, я попробовал свой минимальный воспроизводимый пример и обнаружил, что это не так. происходит.
Вот как я инициализирую TreeView:
Код: Выделить всё
private void createTreeView()
{
this.treeView = new TreeView();
this.grid.Children.Add(this.treeView);
this.Content = this.grid;
TreeViewItem project1 = new TreeViewItem() { Header = "Project 1" ,Padding = new Thickness(20, 0, 0, 0) };
project1.IsExpanded = true;
this.treeView.Items.Add(project1);
this.ListAppSchedHead = new List();
int YEAR = DateTime.Now.Year;
int MONTH = DateTime.Now.Month;
int DAY = DateTime.Now.Day;
this.ListAppSchedHead.Add(new AppSchedHead(APPKEY: 2, ANNDT: new DateTime(YEAR, MONTH, DAY, 9, 0, 0), ENDDT: new DateTime(YEAR, MONTH, DAY, 15, 0, 0), RG: 0));
this.ListAppSchedHead.Add(new AppSchedHead(APPKEY: 3, ANNDT: new DateTime(YEAR, MONTH, DAY, 10, 0, 0), ENDDT: new DateTime(YEAR, MONTH, DAY, 13, 0, 0), RG: 51));
this.ListAppSchedHead.Add(new AppSchedHead(APPKEY: 4, ANNDT: new DateTime(YEAR, MONTH, DAY, 13, 0, 0), ENDDT: new DateTime(YEAR, MONTH, DAY, 16, 0, 0), RG: 51));
this.ListAppSchedHead.Add(new AppSchedHead(APPKEY: 5, ANNDT: new DateTime(YEAR, MONTH, DAY, 13, 0, 0), ENDDT: new DateTime(YEAR, MONTH, DAY, 16, 0, 0), RG: 53));
this.ListAppSchedHead.Add(new AppSchedHead(APPKEY: 6, ANNDT: new DateTime(YEAR, MONTH, DAY, 8, 0, 0), ENDDT: new DateTime(YEAR, MONTH, DAY, 15, 0, 0), RG: 61));
foreach (AppSchedHead item in this.ListAppSchedHead)
{
if (project1.Items.Cast().Where(rgcan => rgcan.RG_ID == item.RG).ToList().Count() == 0)
{
project1.Items.Add(new RessourceTreeViewItem(item.RG ?? 0, dots_per_minute, start_Date, end_Date, item.RG.ToString(), height_of_ressource));
}
RessourceTreeViewItem targetItem = project1.Items.Cast().Where(rgcan => rgcan.RG_ID == item.RG).FirstOrDefault();
if (targetItem != null)
{
targetItem.backgroundcanvas.Children.Add(new TimeLineItem(item.APPKEY.Value, item.WFKKEY, item.ANNDT ?? nan_Date, item.ENDDT ?? nan_Date, dots_per_minute, start_Date, height_of_ressource, tmpintralist));
}
}
project1.Items.Add(listRessourceTreeViewItem);
}
Код: Выделить всё
public partial class TimeLineItem : Grid {
public DateTime start_DT_of_parent { get; set; }
public DateTime StartingAppointment { get; set; }
public DateTime EndingAppointment { get; set; }
public List Intrachildren { get; set;}
public double dots_per_minute { get; set; }
public double duration_min { get; set; }
public double duration_dots { get; set; }
public bool isdraggedoutvertical { get; set; }
private int APPKEY;
public int? WFKKEY { get; set; }
private double left;
private Rectangle rectangle { set; get; }
private double roundfactor;
private double minwidthmin;
public double height { get; set; }
public TimeLineItem(int APPKEY, int? WFKKEY, DateTime StartingAppointment, DateTime EndingAppointment, double dots_per_minute, DateTime start_DT_of_parent, double height, List children)
{
this.height = height;
this.StartingAppointment = StartingAppointment;
this.EndingAppointment = EndingAppointment;
this.APPKEY = APPKEY;
this.WFKKEY = WFKKEY;
this.start_DT_of_parent = start_DT_of_parent;
this.dots_per_minute = dots_per_minute;
this.duration_min = (EndingAppointment - StartingAppointment).TotalMinutes;
this.duration_dots = duration_min * dots_per_minute;
left = (StartingAppointment - start_DT_of_parent).TotalMinutes * dots_per_minute;
roundfactor = dots_per_minute*5;
minwidthmin = 10;
rectangle = new Rectangle();
rectangle.Width = duration_dots;
this.Children.Add(rectangle);
Canvas.SetLeft(this, left);
Canvas.SetTop(this, 0);
}
}
(через targetItem.backgroundcanvas.Children.Add(new TimeLineItem(item. APPKEY.Value, item.WFKKEY, item.ANNDT ?? nan_Date, item.ENDDT ?? nan_Date, dots_per_mine, start_Date, height_of_ressource, tmpintralist));
)
Я могу изменить его размер, как объяснено выше.
Когда у меня подключены дочерние элементы, я не могу указать высоту, this.backgroundcanvas.Height = height_of_ressource; не сохраняется/вычисляется
Подробнее здесь: https://stackoverflow.com/questions/784 ... tpresenter