From a3ebbb6005be58758db28e77be03ce444f2ee7e4 Mon Sep 17 00:00:00 2001 From: Chris Pulman Date: Tue, 1 Oct 2024 23:09:13 +0100 Subject: [PATCH] Update TitleBar to allow Larger Content Update packages --- Directory.Build.props | 2 +- global.json | 4 -- .../CrissCross.WPF.Plot.csproj | 4 +- .../MainWindow.xaml | 5 ++- .../DateTimePicker/DateTimePicker.xaml.cs | 8 +--- .../Controls/GifImage/ImageBehavior.cs | 37 ++++++++++--------- .../Controls/TitleBar/TitleBar.xaml | 2 +- .../CrissCross.WPF.UI.csproj | 6 ++- .../CrissCross.WPF.WebView2.Test.csproj | 2 +- .../CrissCross.WPF.WebView2.csproj | 2 +- src/CrissCross.WPF/CrissCross.WPF.csproj | 2 +- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 9f6c683..86213ce 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -54,7 +54,7 @@ - + diff --git a/global.json b/global.json index 5832575..5cfa01d 100644 --- a/global.json +++ b/global.json @@ -1,8 +1,4 @@ { - "sdk": { - "version": "8.0.10", - "rollForward": "latestFeature" - }, "msbuild-sdks": { "MSBuild.Sdk.Extras": "3.0.44" } diff --git a/src/CrissCross.WPF.Plot/CrissCross.WPF.Plot.csproj b/src/CrissCross.WPF.Plot/CrissCross.WPF.Plot.csproj index 33bc9a2..e3c3a85 100644 --- a/src/CrissCross.WPF.Plot/CrissCross.WPF.Plot.csproj +++ b/src/CrissCross.WPF.Plot/CrissCross.WPF.Plot.csproj @@ -11,7 +11,7 @@ - + @@ -19,7 +19,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/src/CrissCross.WPF.UI.CC_Nav.Test/MainWindow.xaml b/src/CrissCross.WPF.UI.CC_Nav.Test/MainWindow.xaml index 5e359cf..e2a4c73 100644 --- a/src/CrissCross.WPF.UI.CC_Nav.Test/MainWindow.xaml +++ b/src/CrissCross.WPF.UI.CC_Nav.Test/MainWindow.xaml @@ -16,7 +16,10 @@ mc:Ignorable="d"> - + diff --git a/src/CrissCross.WPF.UI/Controls/DateTimePicker/DateTimePicker.xaml.cs b/src/CrissCross.WPF.UI/Controls/DateTimePicker/DateTimePicker.xaml.cs index 16ed71a..f400ae3 100644 --- a/src/CrissCross.WPF.UI/Controls/DateTimePicker/DateTimePicker.xaml.cs +++ b/src/CrissCross.WPF.UI/Controls/DateTimePicker/DateTimePicker.xaml.cs @@ -118,7 +118,7 @@ private void CalDisplay_SelectedDatesChanged(object? sender, EventArgs e) var hours = (Hours?.SelectedItem as ComboBoxItem)?.Content?.ToString() ?? "0"; var minutes = (Min?.SelectedItem as ComboBoxItem)?.Content?.ToString() ?? "0"; var timeSpan = TimeSpan.Parse(hours + ":" + minutes); - if (CalDisplay.SelectedDate.Value.Date == DateTime.Today.Date && timeSpan.CompareTo(DateTime.Now.TimeOfDay) < 0) + if (CalDisplay.SelectedDate!.Value.Date == DateTime.Today.Date && timeSpan.CompareTo(DateTime.Now.TimeOfDay) < 0) { timeSpan = TimeSpan.FromHours(DateTime.Now.Hour + 1); } @@ -134,14 +134,10 @@ private void SaveTime_Click(object sender, RoutedEventArgs e) PopUpCalendarButton.IsChecked = false; } - private void Time_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - CalDisplay_SelectedDatesChanged(sender, e); - } + private void Time_SelectionChanged(object sender, SelectionChangedEventArgs e) => CalDisplay_SelectedDatesChanged(sender, e); private void CalDisplay_PreviewMouseUp(object sender, MouseButtonEventArgs e) { - // that it's not necessary to click twice after opening the calendar https://stackoverflow.com/q/6024372 if (Mouse.Captured is CalendarItem) { Mouse.Capture(null); diff --git a/src/CrissCross.WPF.UI/Controls/GifImage/ImageBehavior.cs b/src/CrissCross.WPF.UI/Controls/GifImage/ImageBehavior.cs index e096502..4d2ecf0 100644 --- a/src/CrissCross.WPF.UI/Controls/GifImage/ImageBehavior.cs +++ b/src/CrissCross.WPF.UI/Controls/GifImage/ImageBehavior.cs @@ -4,7 +4,7 @@ using System.IO; using System.IO.Packaging; -using System.Net; +using System.Net.Http; using System.Text; using System.Windows.Markup; using System.Windows.Media.Animation; @@ -557,7 +557,7 @@ private static void AnimateInDesignModeChanged(DependencyObject o, DependencyPro } } - private static void InitAnimationOrImage(Image imageControl) + private static async void InitAnimationOrImage(Image imageControl) { var controller = GetAnimationController(imageControl); controller?.Dispose(); @@ -597,7 +597,7 @@ void Handler(object? sender, EventArgs args) return; } - var animation = GetAnimation(imageControl, source); + var animation = await GetAnimationAsync(imageControl, source); if (animation != null) { if (animation.KeyFrames.Count > 0) @@ -626,21 +626,22 @@ void Handler(object? sender, EventArgs args) } } - private static ObjectAnimationUsingKeyFrames? GetAnimation(Image imageControl, BitmapSource source) + private static async Task GetAnimationAsync(Image imageControl, BitmapSource source) { var cacheEntry = AnimationCache.Get(source); if (cacheEntry == null) { - if (GetDecoder(source, imageControl, out var gifMetadata) is GifBitmapDecoder decoder && decoder.Frames.Count > 1) + var (bitmapDecoder, gifFile) = await GetDecoderAsync(source, imageControl); + if (bitmapDecoder is GifBitmapDecoder decoder && decoder.Frames.Count > 1) { - var fullSize = GetFullSize(decoder, gifMetadata!); + var fullSize = GetFullSize(decoder, gifFile!); var index = 0; var keyFrames = new ObjectKeyFrameCollection(); var totalDuration = TimeSpan.Zero; BitmapSource? baseFrame = null; foreach (var rawFrame in decoder.Frames) { - var metadata = GetFrameMetadata(decoder, gifMetadata!, index); + var metadata = GetFrameMetadata(decoder, gifFile!, index); var frame = MakeFrame(fullSize, rawFrame, metadata, baseFrame!); var keyFrame = new DiscreteObjectKeyFrame(frame, totalDuration); @@ -673,7 +674,7 @@ void Handler(object? sender, EventArgs args) index++; } - var repeatCount = GetRepeatCountFromMetadata(decoder, gifMetadata!); + var repeatCount = GetRepeatCountFromMetadata(decoder, gifFile!); cacheEntry = new AnimationCacheEntry(keyFrames, totalDuration, repeatCount); AnimationCache.Add(source, cacheEntry); } @@ -729,7 +730,7 @@ private static double GetActualSpeedRatio(Image imageControl, Duration naturalDu return 1.0; } - private static BitmapSource ClearArea(BitmapSource frame, FrameMetadata metadata) + private static WriteableBitmap ClearArea(BitmapSource frame, FrameMetadata metadata) { var visual = new DrawingVisual(); using (var context = visual.RenderOpen()) @@ -782,7 +783,7 @@ private static bool IsLoadingDeferred(BitmapSource source, Image imageControl) return false; } - if (bmp.UriSource != null && !bmp.UriSource.IsAbsoluteUri) + if (bmp.UriSource?.IsAbsoluteUri == false) { return bmp.BaseUri == null && (imageControl as IUriContext)?.BaseUri == null; } @@ -790,9 +791,9 @@ private static bool IsLoadingDeferred(BitmapSource source, Image imageControl) return false; } - private static BitmapDecoder GetDecoder(BitmapSource image, Image imageControl, out GifFile? gifFile) + private static async Task<(BitmapDecoder bitmapDecoder, GifFile gifFile)> GetDecoderAsync(BitmapSource image, Image imageControl) { - gifFile = null; + GifFile? gifFile = default; BitmapDecoder? decoder = null; Stream? stream = null; Uri? uri = null; @@ -831,7 +832,7 @@ private static BitmapDecoder GetDecoder(BitmapSource image, Image imageControl, stream.Position = 0; decoder = BitmapDecoder.Create(stream, createOptions, BitmapCacheOption.OnLoad); } - else if (uri != null && uri.IsAbsoluteUri) + else if (uri?.IsAbsoluteUri == true) { decoder = BitmapDecoder.Create(uri, createOptions, BitmapCacheOption.OnLoad); } @@ -846,7 +847,7 @@ private static BitmapDecoder GetDecoder(BitmapSource image, Image imageControl, } else if (uri != null) { - gifFile = DecodeGifFile(uri); + gifFile = await DecodeGifFileAsync(uri); } else { @@ -859,7 +860,7 @@ private static BitmapDecoder GetDecoder(BitmapSource image, Image imageControl, throw new InvalidOperationException("Can't get a decoder from the source. AnimatedSource should be either a BitmapImage or a BitmapFrame."); } - return decoder; + return (decoder, gifFile!); } private static bool CanReadNativeMetadata(BitmapDecoder decoder) @@ -875,7 +876,7 @@ private static bool CanReadNativeMetadata(BitmapDecoder decoder) } } - private static GifFile? DecodeGifFile(Uri uri) + private static async Task DecodeGifFileAsync(Uri uri) { Stream? stream = default; if (uri.Scheme == PackUriHelper.UriSchemePack) @@ -897,8 +898,8 @@ private static bool CanReadNativeMetadata(BitmapDecoder decoder) } else { - var wc = new WebClient(); - stream = wc.OpenRead(uri); + using var httpClient = new HttpClient(); + stream = await httpClient.GetStreamAsync(uri); } if (stream != null) diff --git a/src/CrissCross.WPF.UI/Controls/TitleBar/TitleBar.xaml b/src/CrissCross.WPF.UI/Controls/TitleBar/TitleBar.xaml index ff1b31b..6546d0a 100644 --- a/src/CrissCross.WPF.UI/Controls/TitleBar/TitleBar.xaml +++ b/src/CrissCross.WPF.UI/Controls/TitleBar/TitleBar.xaml @@ -84,7 +84,7 @@ - + diff --git a/src/CrissCross.WPF.UI/CrissCross.WPF.UI.csproj b/src/CrissCross.WPF.UI/CrissCross.WPF.UI.csproj index d52b868..c352a3d 100644 --- a/src/CrissCross.WPF.UI/CrissCross.WPF.UI.csproj +++ b/src/CrissCross.WPF.UI/CrissCross.WPF.UI.csproj @@ -14,6 +14,10 @@ + + + + @@ -25,7 +29,7 @@ - + diff --git a/src/CrissCross.WPF.WebView2.Test/CrissCross.WPF.WebView2.Test.csproj b/src/CrissCross.WPF.WebView2.Test/CrissCross.WPF.WebView2.Test.csproj index 651acbd..1ade663 100644 --- a/src/CrissCross.WPF.WebView2.Test/CrissCross.WPF.WebView2.Test.csproj +++ b/src/CrissCross.WPF.WebView2.Test/CrissCross.WPF.WebView2.Test.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/CrissCross.WPF.WebView2/CrissCross.WPF.WebView2.csproj b/src/CrissCross.WPF.WebView2/CrissCross.WPF.WebView2.csproj index 344cc17..f57e49b 100644 --- a/src/CrissCross.WPF.WebView2/CrissCross.WPF.WebView2.csproj +++ b/src/CrissCross.WPF.WebView2/CrissCross.WPF.WebView2.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/CrissCross.WPF/CrissCross.WPF.csproj b/src/CrissCross.WPF/CrissCross.WPF.csproj index 6b6e3b1..ad98bac 100644 --- a/src/CrissCross.WPF/CrissCross.WPF.csproj +++ b/src/CrissCross.WPF/CrissCross.WPF.csproj @@ -12,7 +12,7 @@ - +