This commit is contained in:
James Clancey 2019-06-22 23:20:21 -08:00
Родитель a0c92b7657
Коммит 4cccef78c2
3 изменённых файлов: 17 добавлений и 6 удалений

Просмотреть файл

@ -39,7 +39,7 @@ namespace HotUI.Forms.Sample {
Text = state.Text,
Completed =(e)=> state.Text = e
}
: new Label { TextBinding = () => $"{state.Text}: multiText" }),// Fromated Text will warn you. This should be done by TextBinding
: new Label { FormatedText = () => $"{state.Text}: multiText" }),// Fromated Text will warn you. This should be done by TextBinding
new Label {Text = state.Text},
new Button{Text = "Toggle Entry/Label", OnClick = ()=> state.CanEdit = !state.CanEdit},
new Button{Text = "Update Text", OnClick = ()=>{

Просмотреть файл

@ -36,7 +36,7 @@ namespace HotUI.Samples {
Text = state.Text,
Completed =(e)=> state.Text = e
}
: new Label { TextBinding = () => $"{state.Text}: multiText" }),// Fromated Text will warn you. This should be done by TextBinding
: new Label { FormatedText = () => $"{state.Text}: multiText" }),// Fromated Text will warn you. This should be done by TextBinding
new Label {Text = state.Text},
new Button{Text = "Toggle Entry/Label", OnClick = ()=> state.CanEdit = !state.CanEdit},
new Button{Text = "Update Text", OnClick = ()=>{

Просмотреть файл

@ -2,25 +2,36 @@
using System.Diagnostics;
namespace HotUI {
public class Label : View {
public Label()
{
}
public Label(string text)
{
Text = text;
}
public Label(Func<string> formatedText)
{
FormatedText = formatedText;
}
private string text;
public string Text {
get => text;
set => this.SetValue (State, ref text, value, ViewPropertyChanged);
}
public Func<string> TextBinding { get; set; }
public Func<string> FormatedText { get; set; }
protected override void WillUpdateView ()
{
base.WillUpdateView ();
if (TextBinding != null) {
if (FormatedText != null) {
State.StartProperty ();
var text = TextBinding.Invoke ();
var text = FormatedText.Invoke ();
var props = State.EndProperty ();
var propCount = props.Length;
if (propCount > 0) {
State.BindingState.AddViewProperty (props, (s, o) => Text = TextBinding.Invoke ());
State.BindingState.AddViewProperty (props, (s, o) => Text = FormatedText.Invoke ());
}
Text = text;
}