I'm following Jeff Prosise's MSDN tutorial (http://msdn.microsoft.com/en-us/magazine/cc721611.aspx) on creating custom controls. But when I create generic.xaml and bind it to my custom buttom, IE still shows an empty button.
This is mybutton class
public class MyButton : ContentControl { public MyButton() { this.DefaultStyleKey = typeof (MyButton); } }
rshelby: The approach you describe is for defining custom styles in resources. But the above is for defining the default template on custom controls, and you dont define key names in generic.xaml like this.
I wonder if the prefix MyButton is confusing Silverlight, since this is the same name as the class. Try changing it to something else (I usually use local: for the assembly namespace).
--
/Morten | Silverlight MVP | blog - twitter Please click on "Mark as Answer" if this answered your question.
bgnSL
Member
17 Points
28 Posts
Custom control doesn't take data from generic.xaml
Jun 26, 2009 03:54 PM | LINK
I'm following Jeff Prosise's MSDN tutorial (http://msdn.microsoft.com/en-us/magazine/cc721611.aspx) on creating custom controls. But when I create generic.xaml and bind it to my custom buttom, IE still shows an empty button.
This is mybutton class
generic.xaml custom control
Click 'Mark as Answer' if my reply helped you!
Thanks
rshelby
Member
305 Points
75 Posts
Re: Custom control doesn't take data from generic.xaml
Jun 27, 2009 02:46 AM | LINK
Try adding a key name to your style.
For example:
<Style x:Key="myButtonStyle" TargetType="MyButton:MyButton">
Then reference the name from your button control like so:
<MyButton:MyButton Style="{StaticResource myButtonStyle}" />
Hope this helps.
rshelby
SharpGIS
Contributor
4835 Points
832 Posts
Re: Custom control doesn't take data from generic.xaml
Jun 27, 2009 04:50 AM | LINK
rshelby: The approach you describe is for defining custom styles in resources. But the above is for defining the default template on custom controls, and you dont define key names in generic.xaml like this.
I wonder if the prefix MyButton is confusing Silverlight, since this is the same name as the class. Try changing it to something else (I usually use local: for the assembly namespace).
/Morten | Silverlight MVP | blog - twitter
Please click on "Mark as Answer" if this answered your question.
Krasshirsch
Participant
1152 Points
361 Posts
Re: Custom control doesn't take data from generic.xaml
Jun 27, 2009 01:50 PM | LINK
The Generic.xaml file needs to be placed inside the folder Themes, since SL 2 RTW.
Crazy Expensive Bail > (Years You've been Bros) * $100
Alexander Wieser
Germany
bgnSL
Member
17 Points
28 Posts
Re: Re: Custom control doesn't take data from generic.xaml
Jun 29, 2009 09:50 AM | LINK
When I moved it to a folder Themes, the miracle happened :)
Thanks.
Click 'Mark as Answer' if my reply helped you!
Thanks