public App() { InitializeComponent(); //MainPage = new Lab1JCPage(); MainPage = new FormatPage(); }
private void FillAllowedFormats(float?maxHeight, float?maxWidth) { if (!maxHeight.HasValue || !maxWidth.HasValue) { _allowedFormats = GlobalDictionaries.Formats; return; } _allowedFormats = new List <FormatPage>(); FormatPage prevFormat = null; bool? useStandartSizes = null; foreach (var format in GlobalDictionaries.Formats) { if (format.Height > maxHeight || format.Width > maxWidth) { prevFormat = format; continue; } if (useStandartSizes.HasValue) { if (useStandartSizes.Value) { _allowedFormats.Add(format); } else { reduceSize(ref maxWidth, ref maxHeight); _allowedFormats.Add(new FormatPage { Name = format.Name, Height = maxHeight.Value, Width = maxWidth.Value }); } } else { if (format.EqualsWithBackslash(maxWidth.Value, maxHeight.Value, Backlash)) { _allowedFormats.Add(new FormatPage { Name = format.Name, Height = maxHeight.Value, Width = maxWidth.Value }); useStandartSizes = false; } else if (prevFormat != null && prevFormat.EqualsWithBackslash(maxWidth.Value, maxHeight.Value, Backlash)) { _allowedFormats.Add(new FormatPage { Name = prevFormat.Name, Height = maxHeight.Value, Width = maxWidth.Value }); reduceSize(ref maxWidth, ref maxHeight); _allowedFormats.Add(new FormatPage { Name = format.Name, Height = maxHeight.Value, Width = maxWidth.Value }); useStandartSizes = false; } else { _allowedFormats.Add(new FormatPage { Name = "Максимальный размер", Height = maxHeight.Value, Width = maxWidth.Value }); _allowedFormats.Add(format); useStandartSizes = true; } } } if (_allowedFormats.Count == 0) { _allowedFormats.Add(new FormatPage { Name = "Максимальный размер", Width = maxWidth.Value, Height = maxHeight.Value }); } }