solidcolorbrush

Why is the Canvas' Background property a generic “SolidColorBrush” instead of an actual color?

巧了我就是萌 提交于 2019-12-25 01:44:26
问题 I want to respond to a tap on a canvas and store the value of the canvas' background in app settings so that I can assign that value to the AppBar / Command Bar. So I have this XAML in a User Control: <StackPanel Orientation="Horizontal"> <Canvas Background="Aqua" Width="20" Height="20" VerticalAlignment="Center" Tapped="CanvasColor_Tapped"></Canvas> <TextBlock Text="Aqua" VerticalAlignment="Center" Tapped="CanvasColor_Tapped" ></TextBlock> </StackPanel> ..and the handler is: private void

How do I prevent memory leak from SolidColorBrush object?

瘦欲@ 提交于 2019-12-11 05:53:12
问题 There's no option to dispose SolidColorBrush. How do I prevent memory leak from SolidColorBrush object? I can't even use 'using' as SolidColorBrush doesn't implement IDisposable Interface. 回答1: Don't create new SolidColorBrush instances. Use the predefined brushes in System.Windows.Media.Brushes . Otherwise, create a single instance, and re-use that. 回答2: Here is my experience. If I use below code there is a huge memory leak while running it couple hundred thousand times. SolidColorBrush