Files
Common-VS2019/SacsMobileMaui/Maui/Panels/SamPanel_PropertySummary.cs
T

142 lines
4.7 KiB
C#

using Sarand.Net.Mobile.Maui.Controls;
using Sarand.Net.Mobile.Maui.Layouts;
using Sarand.Net.Mobile.Maui.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sarand.Net.Mobile.Maui.Panels
{
//=======================================================================
public class SamPanel_PropertySummary : SamContentView
{
//-------------------------------------------------------------------
// Definitions.
private class PropertyData
{
public String Caption { get; set; } = "";
public String Value { get; set; } = "";
}
//-------------------------------------------------------------------
// Data members.
private float internalFrameRadiusFactor = 0.8f;
private readonly List<PropertyData> properties = new List<PropertyData>();
// Panel components.
private SamFrame framePanel = new SamFrame();
private SamFrame frameInternal = new SamFrame();
private SamGrid gridProperties = new SamGrid();
//-------------------------------------------------------------------
// Construction.
public SamPanel_PropertySummary()
{
// View properties.
//BackgroundColor = Color.Transparent;
framePanel.CornerRadius = 8.0f;
framePanel.Padding = new Thickness(2.0);
framePanel.BackgroundColor = Colors.Transparent;
framePanel.BorderColor = framePanel.BorderColor;
Content = framePanel;
// Frame.
frameInternal.CornerRadius = framePanel.CornerRadius * internalFrameRadiusFactor;
frameInternal.Padding = new Thickness(0);
frameInternal.BorderColor = Colors.White;
frameInternal.BackgroundColor = Colors.White;
framePanel.Content = frameInternal;
frameInternal.Content = gridProperties;
// Properties grid.
gridProperties.Padding = new Thickness(4.0);
gridProperties.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
gridProperties.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Star });
// Property styling.
DefaultFontSize = new SamLabel().FontSize;
FontSize = DefaultFontSize;
ConfigureComponents();
}
//-------------------------------------------------------------------
// Properties.
public Color BorderColor
{
get { return framePanel.BorderColor; }
set
{
framePanel.BorderColor = value;
framePanel.BackgroundColor = value;
}
}
public Thickness BorderWidth { get { return framePanel.Padding; } set { framePanel.Padding = value; } }
public float CornerRadius
{
get { return framePanel.CornerRadius; }
set
{
framePanel.CornerRadius = value;
frameInternal.CornerRadius = framePanel.CornerRadius * internalFrameRadiusFactor;
}
}
public Color PanelBackgroundColor
{
get { return frameInternal.BackgroundColor; }
set
{
frameInternal.BorderColor = value;
frameInternal.BackgroundColor = value;
}
}
// Property label styling.
public double DefaultFontSize { get; }
public double FontSize { get; set; }
//-------------------------------------------------------------------
// S u m m a r y P r o p e r t i e s
//-------------------------------------------------------------------
public void AddProperty(String caption, String value)
{
properties.Add(new PropertyData() { Caption = caption, Value = value });
RefreshProperties();
}
public void ClearProperties()
{
properties.Clear();
RefreshProperties();
}
private void RefreshProperties()
{
// Clear existing properties.
gridProperties.Children.Clear();
gridProperties.RowDefinitions.Clear();
foreach (PropertyData property in properties)
{
int rowIdx = gridProperties.RowDefinitions.Count;
gridProperties.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
gridProperties.Add(new SamLabel() { Text = property.Caption, FontSize = FontSize, HorizontalOptions = LayoutOptions.End }, 0, rowIdx);
gridProperties.Add(new SamLabel() { Text = property.Value, FontSize = FontSize, HorizontalOptions = LayoutOptions.StartAndExpand, VerticalOptions = LayoutOptions.StartAndExpand }, 1, rowIdx);
}
}
//-------------------------------------------------------------------
// C o n f i g u r e C o m p o n e n t s
//-------------------------------------------------------------------
public override void ConfigureComponents()
{
base.ConfigureComponents();
}
//-------------------------------------------------------------------
// P a n e l E v e n t s
//-------------------------------------------------------------------
//-------------------------------------------------------------------
}
//=======================================================================
}