Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Binding to UserControl FontSize not working
3 replies. Latest Post by kris spring on November 4, 2009.
(0)
kris spring
Member
0 points
3 Posts
11-04-2009 2:52 PM |
I have a UserControl with several buttons on it and that can vary in size depending on where its at on my page. The controls are in static locations and the size will not change dynamically. I originally wanted a way to make the FontSize of the buttons proportional to the size of the UserControl so as to have it automatic, but I couldn't figure out how to get that to work right (if anyone knows how to make this happen, I'm all ears). I then set out to make the FontSize of the buttons to be the same as the FontSize property on the UserControl that is set by its parent UserControl.
This seemed simple enough, and Expression Blend cooked up the following for me: FontSize="{Binding FontSize, ElementName=userControl, Mode=OneWay}. Unfortunately, this fails to work for some unknown reason. I have the x:Name="userControl" set on the UserControl tag and I have tried setting the FontSize on that tag itself and from the parent control and neither work.
I found this post while rummaging for a solution but I wasn't sure if this was similar to my problem: http://forums.silverlight.net/forums/p/122061/275035.aspx#275035
If it helps at all, I am using: Visual Studio 2008, Silverlight 3, and Expression Blend 3
Can anyone provide some insight on this?
11-04-2009 3:24 PM |
Well, I just solved my own problem, w00t! Now if only I had known this 2 hours ago...
Here's the lesson for day 2 on silverlight: FontSize is automatically propogated to buttons (and I image everything else) on a UserControl when it is set from the parent UserControl. Any attempt to DataBind the FontSize stops this mechanism from working.
Working psuedo code:<parent control> <child control1 FontSize="12" /> <child control2 FontSize="22" /><parent control>
Nowhere in the child control's code am I specifying the FontSize
msalsbery
Contributor
2066 points
379 Posts
11-04-2009 3:46 PM |
kris spring: FontSize is automatically propogated to buttons
FWIW.....font property inheritance in controls is discussed in the documentation a bit here: Text and Fonts
11-04-2009 4:03 PM |
Thanks!