How can set usercontrol's template in xaml
how can set usercontrol's template in xaml, xaml this:
<usercontrol x:class="silverlightdemo.usercontrols.testcontrol"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="silverlightdemo.usercontrols"
xmlns:vsm="clr-namespace:system.windows;assembly=system.windows"
width="400" height="300">
<usercontrol.template>
<controltemplate targettype="local:testcontrol">
<grid x:name="layoutroot" background="white">
<vsm:visualstatemanager.visualstategroups>
<vsm:visualstategroup x:name="commonstates">
<vsm:visualstate x:name="mouseover">
<storyboard>
<objectanimationusingkeyframes duration="00:00:00" storyboard.targetname="rectangletest" storyboard.targetproperty="(rectangle.fill)">
<discreteobjectkeyframe keytime="00:00:00">
<discreteobjectkeyframe.value>
<solidcolorbrush color="black"></solidcolorbrush>
</discreteobjectkeyframe.value>
</discreteobjectkeyframe>
</objectanimationusingkeyframes>
</storyboard>
</vsm:visualstate>
</vsm:visualstategroup>
</vsm:visualstatemanager.visualstategroups>
<rectangle x:name="rectangletest" fill="red"></rectangle>
</grid>
</controltemplate>
</usercontrol.template>
</usercontrol>
but runtime give error -> invalid attribute value local:testcontrol property targettype
try putting same visualstates in template inside grid (layoutroot) element of usercontrol!same thing hehe ;)
code-behind of usercontrol write either
visualstatemanager.gotostate(layoutroot, "awesome");
or
visualstatemanager.gotostate(this, "awesome");
vsmanager traverses visual tree until finds element has visualstates defined.
Silverlight > Programming Silverlight with .NET – General
Comments
Post a Comment