1
votes

I've just started developing in Silverlight, and I have a calendar control which shows details for each day.

The text within the calendar is held within lots of textblocks, for some browsers the text size might be too big, so I want to have a slider control on the 'usercontrol' which allows the user to adjust the font size.

I'm building the calendar through c# code, so my question is.. what is the best way to 'wire' this up. I'm guessing it would be one of these options.

  1. Add an event to the slider control for ValueChanged, then iterate through all TextBlocks setting the fontsize to the new size. This seems long-winded.

  2. Maybe using a 'Style', which is attached to each TextBlock, then just changing the FontSize of the 'Style'.. ?? maybe ?

  3. Using 'binding' & 'Dependancy Property'. I've looked into this, and it seems to be the way to do it, but I can't find an example where you're passing a value from one control to multiple other ones. Maybe I'm missing something.

I can do option 1 quite easily, but I want to learn about alternative methods of doing this.

Thanks Rich.

2

2 Answers

0
votes

A way to handle this is to not use fixed sizes but to size everything to its content. that way the control will get bigger when a larger font size is selected. Just like the TextBlock.

0
votes

I've actually got this working now using option 3 which I'm happy with, it was very simple, but there seemed to be little documentation on it (maybe I was searching for the wrong thing).

It was as simple as adding a few lines...

        Binding bind = new Binding("Value");
        bind.Source = FontSlider;

The for every control that I want to apply the FontSlider's 'Value' to.. I do this...

        MyTextBlock.SetBinding(TextBlock.FontSizeProperty,bind);

Simples.

Cheers Rich.