开发者

Silverlight simple binding / dependancy property

开发者 https://www.devze.com 2023-02-19 17:59 出处:网络
I\'ve just started developing in Silverlight, and I have a calendar control which shows details for each day.

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 Pr开发者_StackOverflowoperty'. 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消