provide control developer specified custom style classes and properties
This commit is contained in:
parent
9a4dbda5df
commit
c43eda9152
@ -1,3 +1,4 @@
|
|||||||
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using MBS.Web.UI;
|
using MBS.Web.UI;
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ public abstract class Control : IWebHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<string, string> PathVariables { get; } = new Dictionary<string, string>();
|
public Dictionary<string, string> PathVariables { get; } = new Dictionary<string, string>();
|
||||||
|
public Dictionary<string, string> StyleProperties { get; } = new Dictionary<string, string>();
|
||||||
public bool Visible { get; set; } = true;
|
public bool Visible { get; set; } = true;
|
||||||
|
|
||||||
public Control(Dictionary<string, string>? pathVariables = null)
|
public Control(Dictionary<string, string>? pathVariables = null)
|
||||||
@ -39,6 +41,12 @@ public abstract class Control : IWebHandler
|
|||||||
return new string[0];
|
return new string[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IReadOnlyDictionary<string, string> _emptyStyleProperties = new Dictionary<string, string>();
|
||||||
|
protected virtual IReadOnlyDictionary<string, string> GetStyleProperties()
|
||||||
|
{
|
||||||
|
return _emptyStyleProperties;
|
||||||
|
}
|
||||||
|
|
||||||
private bool _initted = false;
|
private bool _initted = false;
|
||||||
protected void EnsureInitialized()
|
protected void EnsureInitialized()
|
||||||
{
|
{
|
||||||
@ -65,6 +73,8 @@ public abstract class Control : IWebHandler
|
|||||||
writer.WriteStartElement(TagName);
|
writer.WriteStartElement(TagName);
|
||||||
|
|
||||||
bool classListWritten = false;
|
bool classListWritten = false;
|
||||||
|
bool styleListWritten = false;
|
||||||
|
|
||||||
IDictionary<string, string> attrs = GetControlAttributes();
|
IDictionary<string, string> attrs = GetControlAttributes();
|
||||||
foreach (KeyValuePair<string, string> kvp in attrs)
|
foreach (KeyValuePair<string, string> kvp in attrs)
|
||||||
{
|
{
|
||||||
@ -76,6 +86,13 @@ public abstract class Control : IWebHandler
|
|||||||
value = String.Join(' ', classList);
|
value = String.Join(' ', classList);
|
||||||
classListWritten = true;
|
classListWritten = true;
|
||||||
}
|
}
|
||||||
|
else if (kvp.Key == "style")
|
||||||
|
{
|
||||||
|
// IDictionary<string, string> classList = GetStyleProperties().Union(kvp.Value.Split(new char[] { ';' }));
|
||||||
|
|
||||||
|
// value = String.Join(' ', classList);
|
||||||
|
// classListWritten = true;
|
||||||
|
}
|
||||||
writer.WriteAttributeString(kvp.Key, value);
|
writer.WriteAttributeString(kvp.Key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,8 +101,28 @@ public abstract class Control : IWebHandler
|
|||||||
{
|
{
|
||||||
writer.WriteAttributeString("class", String.Join(' ', actualClassList));
|
writer.WriteAttributeString("class", String.Join(' ', actualClassList));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IEnumerable<KeyValuePair<string, string>> actualStyleProperties = GetStyleProperties().Union(StyleProperties);
|
||||||
|
if (!styleListWritten && actualStyleProperties.Count() > 0)
|
||||||
|
{
|
||||||
|
writer.WriteAttributeString("style", RenderStyleProperties(actualStyleProperties));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
protected virtual void RenderEndTag(XmlWriter writer)
|
|
||||||
|
private string RenderStyleProperties(IEnumerable<KeyValuePair<string, string>> actualStyleProperties)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
foreach (KeyValuePair<string, string> kvp in actualStyleProperties)
|
||||||
|
{
|
||||||
|
sb.Append(kvp.Key);
|
||||||
|
sb.Append(':');
|
||||||
|
sb.Append(kvp.Value);
|
||||||
|
sb.Append(';');
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void RenderEndTag(XmlWriter writer)
|
||||||
{
|
{
|
||||||
writer.WriteEndElement();
|
writer.WriteEndElement();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,6 +113,18 @@ public class ListView : Container
|
|||||||
|
|
||||||
private HtmlGenericControl thead = null, tbody = null;
|
private HtmlGenericControl thead = null, tbody = null;
|
||||||
|
|
||||||
|
protected override IEnumerable<string> GetStyleClasses()
|
||||||
|
{
|
||||||
|
return [ "uwt-listview" ];
|
||||||
|
}
|
||||||
|
protected override IReadOnlyDictionary<string, string> GetStyleProperties()
|
||||||
|
{
|
||||||
|
return new Dictionary<string, string>(new KeyValuePair<string, string>[]
|
||||||
|
{
|
||||||
|
new KeyValuePair<string, string>("height", "300px")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected override IList<Control> GetChildControls()
|
protected override IList<Control> GetChildControls()
|
||||||
{
|
{
|
||||||
thead = new HtmlGenericControl("thead");
|
thead = new HtmlGenericControl("thead");
|
||||||
@ -127,6 +139,10 @@ public class ListView : Container
|
|||||||
thead.Controls.Add(tr);
|
thead.Controls.Add(tr);
|
||||||
|
|
||||||
tbody = new HtmlGenericControl("tbody");
|
tbody = new HtmlGenericControl("tbody");
|
||||||
|
tbody.StyleProperties["height"] = "500px";
|
||||||
|
tbody.StyleProperties["overflow"] = "scroll";
|
||||||
|
tbody.StyleProperties["display"] = "block";
|
||||||
|
|
||||||
foreach (ListViewItem lvi in Items)
|
foreach (ListViewItem lvi in Items)
|
||||||
{
|
{
|
||||||
HtmlGenericControl tr2 = new HtmlGenericControl("tr");
|
HtmlGenericControl tr2 = new HtmlGenericControl("tr");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user