using Shared;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace HDL_ON.Stan
|
{
|
/// <summary>
|
/// 做成一个点击后能够显示点击状态的控件(基层控件)
|
/// </summary>
|
public class FrameLayoutStatuControl : FrameLayoutBase
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 状态设置的事件(会重载底层效果)
|
/// </summary>
|
public Action<bool> SelectStatuEvent;
|
/// <summary>
|
/// 子控件Y轴偏移量(共通定义而已)
|
/// </summary>
|
public int chidrenYaxis = 0;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 做成一个点击后能够显示点击状态的控件
|
/// </summary>
|
/// <param name="i_ChidrenYaxis">子控件Y轴偏移量(【列表控件的rowSpace/2】即可,不懂默认为0即可)</param>
|
public FrameLayoutStatuControl(int i_ChidrenYaxis = 0)
|
{
|
this.chidrenYaxis = i_ChidrenYaxis;
|
|
//置空底层的事件
|
this.MouseUpEventHandler = null;
|
this.MouseUpEventHandler += ChildrenUpEvent;
|
}
|
|
#endregion
|
|
#region ■ 绑定事件___________________________
|
|
/// <summary>
|
/// 变更子控件的绑定模式
|
/// </summary>
|
/// <param name="view">子控件</param>
|
/// <param name="chidrenBindMode">变更的绑定模式</param>
|
public void ChangedChidrenBindMode(View view, ChidrenBindMode chidrenBindMode)
|
{
|
if (view is ButtonCtrBase)
|
{
|
//子控件移除事件
|
ButtonCtrBase button = (ButtonCtrBase)view;
|
button.ButtonClickEvent -= ChildrenUpEvent;
|
|
this.BindChidrenEvent(view, chidrenBindMode);
|
}
|
else if (view is ImageView)
|
{
|
view.MouseUpEventHandler -= ChildrenUpEvent;
|
|
this.BindChidrenEvent(view, chidrenBindMode);
|
}
|
else if (view is ViewGroup)
|
{
|
ViewGroup groupContr = (ViewGroup)view;
|
for (int i = 0; i < groupContr.ChildrenCount; i++)
|
{
|
var myView = groupContr.GetChildren(i);
|
if (myView == null)
|
{
|
break;
|
}
|
if (myView is ButtonCtrBase)
|
{
|
//子控件移除事件
|
ButtonCtrBase button = (ButtonCtrBase)myView;
|
button.ButtonClickEvent -= ChildrenUpEvent;
|
}
|
}
|
//自身移除事件
|
groupContr.MouseUpEventHandler -= ChildrenUpEvent;
|
|
this.BindChidrenEvent(view, chidrenBindMode);
|
}
|
}
|
|
/// <summary>
|
/// 绑定子控件事件(如果是复合控件,在初始化完成后,调用ChangedChidrenBindMode)
|
/// </summary>
|
/// <param name="view"></param>
|
/// <param name="chidrenBindMode"></param>
|
private void BindChidrenEvent(View view, ChidrenBindMode chidrenBindMode)
|
{
|
if (chidrenBindMode == ChidrenBindMode.NotBind)
|
{
|
return;
|
}
|
if (view is ButtonCtrBase)
|
{
|
//为子控件添加事件
|
ButtonCtrBase button = (ButtonCtrBase)view;
|
button.ButtonClickEvent -= ChildrenUpEvent;
|
button.ButtonClickEvent += ChildrenUpEvent;
|
}
|
else if (view is ImageView)
|
{
|
//自身也添加事件
|
view.MouseUpEventHandler -= ChildrenUpEvent;
|
view.MouseUpEventHandler += ChildrenUpEvent;
|
}
|
else if (view is ViewGroup)
|
{
|
//为子控件添加事件
|
ViewGroup groupContr = (ViewGroup)view;
|
for (int i = 0; i < groupContr.ChildrenCount; i++)
|
{
|
var myView = groupContr.GetChildren(i);
|
if (myView == null)
|
{
|
break;
|
}
|
if (myView is ButtonCtrBase)
|
{
|
//为子控件添加事件
|
ButtonCtrBase button = (ButtonCtrBase)myView;
|
button.ButtonClickEvent -= ChildrenUpEvent;
|
button.ButtonClickEvent += ChildrenUpEvent;
|
}
|
}
|
//自身也添加事件
|
groupContr.MouseUpEventHandler -= ChildrenUpEvent;
|
groupContr.MouseUpEventHandler += ChildrenUpEvent;
|
}
|
}
|
|
#endregion
|
|
#region ■ 添加子控件_________________________
|
|
/// <summary>
|
/// 添加子控件
|
/// </summary>
|
/// <param name="view">子控件</param>
|
/// <param name="chidrenBindMode">绑定模式</param>
|
public void AddChidren(View view, ChidrenBindMode chidrenBindMode = ChidrenBindMode.BindEvent)
|
{
|
base.AddChidren(view);
|
|
//绑定子控件事件
|
this.BindChidrenEvent(view, chidrenBindMode);
|
}
|
|
/// <summary>
|
/// 添加子控件
|
/// </summary>
|
/// <param name="view"></param>
|
public override void AddChidren(View view)
|
{
|
this.AddChidren(view, ChidrenBindMode.NotBind);
|
}
|
|
#endregion
|
|
#region ■ 控件事件___________________________
|
|
/// <summary>
|
/// 点击松开事件
|
/// </summary>
|
/// <param name="sender">Sender.</param>
|
/// <param name="e">E.</param>
|
private void ChildrenUpEvent(object sender, MouseEventArgs e)
|
{
|
if (this.CanClick == false)
|
{
|
//不允许点击
|
return;
|
}
|
try
|
{
|
//调用委托
|
ButtonClickEvent?.Invoke(sender, e);
|
}
|
catch (Exception ex)
|
{
|
//出现未知错误
|
HdlMessageLogic.Current.ShowAppProgramIsError(ex);
|
}
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 移除底层控件自身的单击事件
|
/// </summary>
|
public void RemoveBaseClickEvent()
|
{
|
this.MouseUpEventHandler -= ChildrenUpEvent;
|
}
|
|
/// <summary>
|
/// 控件摧毁
|
/// </summary>
|
public override void RemoveFromParent()
|
{
|
this.SelectStatuEvent = null;
|
|
base.RemoveFromParent();
|
}
|
|
#endregion
|
}
|
}
|