private async void ComboBoxResolution_TextSubmitted(ComboBox sender, ComboBoxTextSubmittedEventArgs args)
 {
     await RunOnUIThreadAndWaitAsync(CoreDispatcherPriority.High, () =>
     {
         if (int.TryParse(args.Text, out int intValue))
         {
             // entered pure number, try to apply it
             ScanResolution resolution = ViewModel.ScannerResolutions.FirstOrDefault((x) => x.Resolution.DpiX == intValue);
             if (resolution != null)
             {
                 // found corresponding resolution
                 ViewModel.SelectedResolution = resolution;
             }
             else
             {
                 // no resolution for number, find the closest available one
                 resolution = ViewModel.ScannerResolutions.Aggregate((x, y) => Math.Abs(x.Resolution.DpiX - intValue) < Math.Abs(y.Resolution.DpiX - intValue) ? x : y);
                 ViewModel.SelectedResolution = resolution;
             }
         }
         else
         {
             sender.SelectedItem = ViewModel.SelectedResolution;
             args.Handled        = true;
         }
     });
 }
Esempio n. 2
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is ScanResolution))
            {
                return(DependencyProperty.UnsetValue);
            }

            ScanResolution resolution = (ScanResolution)value;

            return(string.Format("{0} × {1}", resolution.Width, resolution.Height));
        }