Put the RBC number text below border on the main image.
[master-thesis.git] / Parasitemia / ParasitemiaUIControls / RBCFrame.xaml.cs
1 ´╗┐using System.Windows.Controls;
2
3 namespace ParasitemiaUIControls
4 {
5     public partial class RBCFrame : UserControl
6     {
7         bool isTextBelow = false;
8
9         public RBCFrame()
10         {
11             this.InitializeComponent();
12             this.borderRBCNumber.SizeChanged += BorderRBCNumber_SizeChanged;
13         }
14
15         public bool IsTextBelow
16         {
17             get => this.isTextBelow;
18             set
19             {
20                 if (value != this.isTextBelow)
21                 {
22                     this.isTextBelow = value;
23                     this.UpdateRBCNumberPosition();
24                 }
25             }
26         }
27
28         void BorderRBCNumber_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
29         {
30             this.UpdateRBCNumberPosition();
31
32             //this.UpdateLayout();
33             //System.Diagnostics.Debug.WriteLine($"ActuaSize: {this.borderRBCNumber.ActualHeight}");
34         }
35
36         void UpdateRBCNumberPosition()
37         {
38             var m = this.borderRBCNumber.Margin;
39
40             m.Bottom =
41                 this.isTextBelow
42                     ? - this.borderRBCNumber.ActualHeight - 0.05 * this.borderRBCNumber.ActualHeight
43                     : 0.05 * this.borderRBCNumber.ActualHeight;
44
45             this.borderRBCNumber.Margin = m;
46         }
47     }
48 }