Silverlight 简单绑定/依赖属性
我刚刚开始在 Silverlight 中进行开发,并且我有一个日历控件,可以显示每天的详细信息。
日历中的文本保存在许多文本块中,对于某些浏览器来说,文本大小可能太大,所以我想在“用户控件”上有一个滑块控件,允许用户调整字体大小。
我正在通过 C# 代码构建日历,所以我的问题是..“连接”它的最佳方法是什么。我猜这将是这些选项之一。
将事件添加到 ValueChanged 的滑块控件,然后迭代所有 TextBlock,将字体大小设置为新大小。这看起来很冗长。
也许使用附加到每个 TextBlock 的“样式”,然后只需更改“样式”的字体大小..?也许?
使用“绑定”& “附属财产”。我已经研究过这一点,这似乎是实现这一点的方法,但我找不到将值从一个控件传递到多个其他控件的示例。也许我遗漏了一些东西。
我可以很轻松地执行选项 1,但我想了解执行此操作的替代方法。
谢谢 富有的。
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.
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.
Maybe using a 'Style', which is attached to each TextBlock, then just changing the FontSize of the 'Style'.. ?? maybe ?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决这个问题的一种方法是不使用固定大小,而是根据其内容调整所有内容的大小。这样,当选择更大的字体大小时,控件将变得更大。就像文本块一样。
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.
实际上,我现在已经使用我很满意的选项 3 完成了这项工作,它非常简单,但似乎很少有关于它的文档(也许我正在寻找错误的东西)。
就像添加几行一样简单......
对于我想要应用 FontSlider 的“值”的每个控件......我这样做......
简单。
干杯
富有的。
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...
The for every control that I want to apply the FontSlider's 'Value' to.. I do this...
Simples.
Cheers
Rich.