Need help getting started with customizing controls
hi again
after reading through of documentation ships silverlight, understand bit better. optimistic set out build silverlight version of ui wordpress administration page (screenshot can found on http://wordpress.org/), have go by, since no means designer.
i ran in problems. tried best, following various guides , watching videos customize button make in wordpress admin ui, not working.
if understand xaml correctly, once learn customize 1 control, can customize them all.
so, if kind me guide on how make classic "html link" button in silverlight, you, when hover button, text changes color. able indicate button selected 1 (consider stackpanel 5 buttons, used navigation).
regards, egil.
hi:
can try this:
generic.xaml:
<resourcedictionary
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:silverlightapplication12;assembly=silverlightapplication12" mce_src="clr-namespace:silverlightapplication12;assembly=silverlightapplication12"
xmlns:vsm="clr-namespace:system.windows;assembly=system.windows"
>
<style targettype="src:linkbutton">
<setter property="template">
<setter.value>
<controltemplate targettype="src:linkbutton">
<stackpanel x:name="mainpanel" height="{templatebinding height}" width="{templatebinding width}" background="{templatebinding background}">
<textblock x:name="linktext" textdecorations="underline" fontfamily="{templatebinding fontfamily}" fontsize="{templatebinding fontsize}" fontstyle="{templatebinding fontstyle}" foreground="{templatebinding foreground}" />
</stackpanel>
</controltemplate>
</setter.value>
</setter>
</style>
</resourcedictionary>
linkbutton.cs:
using system;
using system.net;
using system.windows;
using system.windows.controls;
using system.windows.documents;
using system.windows.ink;
using system.windows.input;
using system.windows.media;
using system.windows.media.animation;
using system.windows.shapes;
using system.windows.browser;
namespace silverlightapplication12
{
public class linkbutton : button
{
public string navigationuri { get; set; }
public string target { get; set; }
public new brush foreground { { return tb.foreground; } set { tb.foreground = value;} }
static linkbutton selectedlink = null;
brush normalbrush = new solidcolorbrush(color.fromargb(255, 0, 0, 0));
brush selectbrush = new solidcolorbrush(color.fromargb(255, 200, 100, 100));
brush hoverbrush = new solidcolorbrush(color.fromargb(255, 100, 100, 200));
textblock tb = null;
public linkbutton()
{
defaultstylekey = typeof(linkbutton);
}
public override void onapplytemplate()
{
base.onapplytemplate();
stackpanel sp = (stackpanel)gettemplatechild("mainpanel");
tb = (textblock)gettemplatechild("linktext");
tb.text = this.content.tostring();
sp.mouseleftbuttonup += new mousebuttoneventhandler(sp_mouseleftbuttonup);
sp.mouseenter += new mouseeventhandler(sp_mouseenter);
sp.mouseleave += new mouseeventhandler(sp_mouseleave);
}
void sp_mouseleave(object sender, mouseeventargs e)
{
if (!this.equals(selectedlink))
tb.foreground = normalbrush;
else
tb.foreground = selectbrush;
}
void sp_mouseenter(object sender, mouseeventargs e)
{
tb.foreground = hoverbrush;
}
void sp_mouseleftbuttonup(object sender, mousebuttoneventargs e)
{
if (selectedlink != null)
{
selectedlink.foreground = normalbrush;
tb.foreground = selectbrush;
}
selectedlink = this;
if (navigationuri != null)
{
if (target!=null)
{ htmlpage.window.navigate(new uri(navigationuri), target); }
else
{
htmlpage.window.navigate(new uri(navigationuri));
}
}
}
}
}
to test:
<stackpanel x:name="layoutroot" background="white">
<c:linkbutton navigationuri="http://www.microsoft.com" fontsize="50" x:name="link1" width="200" height="100" content="hello"></c:linkbutton>
<c:linkbutton navigationuri="http://www.microsoft.com" target="_blank" x:name="link2" width="200" height="100" content="hello" ></c:linkbutton>
<c:linkbutton background="yellow" x:name="link3" width="200" height="100" content="hello" ></c:linkbutton>
</stackpanel>
regards
Silverlight > Getting Started with Silverlight
Comments
Post a Comment