razor支持

This commit is contained in:
小红帽 2024-01-09 17:47:19 +08:00
parent ac3faaa8ed
commit 09727c75e1
2 changed files with 17 additions and 6 deletions

View File

@ -87,15 +87,19 @@ namespace CPF.Razor.Controls
} }
Dictionary<string, ulong> handlerIds = new Dictionary<string, ulong>(); Dictionary<string, ulong> handlerIds = new Dictionary<string, ulong>();
/// <summary>
/// 事件
/// </summary>
HashSet<string> events = new HashSet<string>(); HashSet<string> events = new HashSet<string>();
/// <summary> /// <summary>
/// 元素属性 /// 元素属性
/// </summary> /// </summary>
Dictionary<string, System.Reflection.PropertyInfo> ePs = new Dictionary<string, System.Reflection.PropertyInfo>(); Dictionary<string, PropertyInfo> ePs = new Dictionary<string, PropertyInfo>();
/// <summary> /// <summary>
/// 依赖属性用于绑定通知TextChanged /// 依赖属性用于绑定通知TextChanged
/// </summary> /// </summary>
Dictionary<string, System.Reflection.PropertyInfo> cPs = new Dictionary<string, System.Reflection.PropertyInfo>(); Dictionary<string, PropertyInfo> cPs = new Dictionary<string, PropertyInfo>();
protected override T CreateElement() protected override T CreateElement()
{ {
@ -136,7 +140,7 @@ namespace CPF.Razor.Controls
events.Add(name); events.Add(name);
} }
r.Commands.Add(nameof(r.PropertyChanged), (s, e) => r.Commands.Add(nameof(r.PropertyChanged), (s, e) =>
{ {//属性变换通知事件给onXXXChanged
var pe = (CPFPropertyChangedEventArgs)e; var pe = (CPFPropertyChangedEventArgs)e;
if (handlerIds.TryGetValue("on" + pe.PropertyName + "Changed", out var id)) if (handlerIds.TryGetValue("on" + pe.PropertyName + "Changed", out var id))
{ {
@ -154,7 +158,11 @@ namespace CPF.Razor.Controls
return r; return r;
} }
/// <summary>
/// 处理标签内部文字
/// </summary>
/// <param name="index"></param>
/// <param name="text"></param>
public void HandleText(int index, string text) public void HandleText(int index, string text)
{ {
if (Element is CPF.Controls.ContentControl control) if (Element is CPF.Controls.ContentControl control)
@ -162,7 +170,10 @@ namespace CPF.Razor.Controls
control.Content = text; control.Content = text;
} }
} }
/// <summary>
/// 实现Razor控件自动转换成CPF控件
/// </summary>
/// <param name="element"></param>
public static implicit operator T(Element<T> element) public static implicit operator T(Element<T> element)
{ {
return element.Element; return element.Element;

View File

@ -7,7 +7,7 @@
{ {
<Panel Background="#0f0" Width="20" Height="30" MarginLeft="10"></Panel> <Panel Background="#0f0" Width="20" Height="30" MarginLeft="10"></Panel>
} }
<TextBox @ref="textBox" Text="text" Width="100" Height="30" TextChanged="TextChanged"></TextBox> <TextBox @ref="textBox" @bind-Text="text" Width="100" Height="30"></TextBox>
<Button @ref="button"><CheckBox>@enable</CheckBox></Button> <Button @ref="button"><CheckBox>@enable</CheckBox></Button>
<ListBox @ref="listBox" Width="200" Height="200" Items="list"></ListBox> <ListBox @ref="listBox" Width="200" Height="200" Items="list"></ListBox>
</StackPanel> </StackPanel>