0
public class Notifications: ObservableCollection <Notification> {}
public Notifications Notifications = new Notifications();
private readonly Queue <Notification> buffer = new Queue <Notification>();
public NotificationsWindows() {
InitializeComponent();
NotificationsControl.DataContext = Notifications;
this.Height = SystemParameters.WorkArea.Height;
this.Width = SystemParameters.WorkArea.Width/3;
this.Left = SystemParameters.WorkArea.Left + SystemParameters.WorkArea.Width - this.Width;
this.Top = SystemParameters.WorkArea.Top;
}
public void AddNotification(Notification notification) {
notification.Id = count++;
if (NotificationsControl.ActualHeight + * what would be the size of the notification we want to add * > SystemParameters.WorkArea.Height) {
buffer.Enqueue(notification);
} else {
if (corner == 0 || corner == 3) {
Notifications.Insert(0, notification);
} else {
Notifications.Add(notification);
}
}
//Show window if there're notifications
if (Notifications.Count > 0 && !IsActive) Show();
}
다음 코드는 WPF 창 클래스이며 NotificationsControl은«Notifications»컬렉션을 통해 데이터 템플릿을 적용하는 항목 컨트롤입니다. 화면의 높이를 모두 사용할 때 멈추는 화면에 경고 메시지를 표시하려고하므로 데이터 템플릿에 적용될 때 알림의 크기를 계산해야합니다. 가능한가?DataTemplate 생성 요소의 크기를 계산하지 않고
그래도 필요한 경우 측정에서 봐, 그리고 방법을 마련 확실하지 않음 이 [MSDN] (https://msdn.microsoft.com/en-us/library/ms745058(v=vs.110) .aspx # LayoutSystem_Measure_Arrange) 페이지를 방문하십시오. datacontext가 업데이트 된 후이 메서드를 실행하면 새 크기를 가져올 수 있습니다. 원하는 크기보다 큰 경우 datacontext에서 알림을 제거하십시오. 이 메서드는 Label 크기와 함께 한 번 사용 했으므로 다른 UIElements와도 함께 사용해야합니다. –
@Attila 감사합니다. MeasureOverride를 사용하여 작업하고 있습니다. :) –