/*------------------------------------------------------------------------- // UNCLASSIFIED /*------------------------------------------------------------------------- RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON COMPANY. THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT. UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY. -------------------------------------------------------------------------*/ using System; using System.Collections.Specialized; using System.Windows; using System.Windows.Media.Imaging; using ProgramLib.GUI.Model; using ProgramLib.GUI.ViewModel; namespace ProgramLib.GUI.View { /// /// Interaction logic for ImpedanceCheckWindow.xaml /// internal partial class ImpedanceCheckWindow : Window { internal ImpedanceCheckWindowViewModel ViewModel { get; set; } private double _previousWindowWidth = -1.0; public ImpedanceCheckWindow() { InitializeComponent(); Uri iconUri = new Uri($"pack://application:,,,/{GetType().Assembly.GetName().Name};component/Resources/Icons/app.ico"); this.Icon = BitmapFrame.Create(iconUri); WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; btnClose.Visibility = Visibility.Hidden; ((INotifyCollectionChanged)lvImpedanceCheck.Items).CollectionChanged += ListView_CollectionChanged; ViewModel = new ImpedanceCheckWindowViewModel(this); DataContext = ViewModel; } protected override void OnContentRendered(EventArgs e) { base.OnContentRendered(e); // call the delegate to perform STTO } private void Window_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { DragMove(); } private void btnClose_Click(object sender, RoutedEventArgs e) { this.Hide(); } private void ListView_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { // scroll the new item into view lvImpedanceCheck.ScrollIntoView(e.NewItems[0]); ResizeWindowToFitContent(); } } /// /// Resize window to fit variable text length /// private void ResizeWindowToFitContent() { bool resizeWindow = false; double textLength = ProgramLib.GUI.Util.MeasureString(((ImpedanceDataModel)lvImpedanceCheck.Items[lvImpedanceCheck.Items.Count - 1]).Description).Width; double padding = 90.0; double requiredWith = textLength + padding; if (lvImpedanceCheck.Items.Count > 1) { if (requiredWith > this.Width) resizeWindow = true; } else { _previousWindowWidth = this.Width; resizeWindow = true; } if (resizeWindow) this.Width = requiredWith; } } }