using CPF;
using CPF.Animation;
using CPF.Charts;
using CPF.Controls;
using CPF.Drawing;
using CPF.Shapes;
using CPF.Styling;
using CPF.Svg;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp1
{
[CPF.Design.DesignerLoadStyle("res://ConsoleApp1/Stylesheet1.css")]//用于设计的时候加载样式
public class ListBoxItem1 : ListBoxItem
{
//public (string title, string host) vdata;
public vd vdata;
public string SvgSource
{
get
{
return (string)GetValue();
}
set
{
SetValue(value);
}
}
public bool HostState
{
set
{
if (value)
{
SvgSource = "";
}
else
{
SvgSource = "";
}//d4237a
}
}
//模板定义
protected override void InitializeComponent()
{
//模板定义
//CornerRadius="15";
//BorderFill = "#000";
//BorderStroke = "1";
if (DesignMode)
{
Width = 200;
}
else
{
Width = "100%";
}
Height = 40;
Background = "#fff";
Children.Add(new SVG
{
IsAntiAlias = true,
Size = "22,22",
Stretch = Stretch.Uniform,
Width = 30,
Height = 30,
MarginLeft = 5,
Bindings = {
{ nameof(SVG.Source),nameof(SvgSource),this}
}
});
Children.Add(new TextBlock
{
Text = vdata.title,
MarginLeft = 40,
MarginTop = 5,
});
Children.Add(new TextBlock
{
Text = vdata.host,
MarginLeft = 40,
MarginTop = 20,
Foreground = "#666",
});
Triggers.Add(new Trigger
{
Property = nameof(IsMouseOver),
PropertyConditions = a => (bool)a && !IsSelected,
Setters =
{
{
nameof(Background),
"229,243,251"
}
}
});
Triggers.Add(new Trigger
{
Property = nameof(IsSelected),
PropertyConditions = a => (bool)a,
Setters =
{
{
nameof(Background),
"203,233,246"
}
}
});
}
}
public struct vd
{
public string title { set; get; }
public string host { set; get; }
}
}