Skip to main content

Microsoft Silverlight

Answered Question Binding to UserControl FontSize not workingRSS Feed

(0)

kris spring
kris spring

Member

Member

0 points

3 Posts

Binding to UserControl FontSize not working

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?

kris spring
kris spring

Member

Member

0 points

3 Posts

Answered Question

Re: Binding to UserControl FontSize not working

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
msalsbery

Contributor

Contributor

2066 points

379 Posts

Re: Binding to UserControl FontSize not working

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

 

Mark Salsbery
Microsoft MVP - Visual C++

kris spring
kris spring

Member

Member

0 points

3 Posts

Re: Binding to UserControl FontSize not working

Thanks!

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities