Silverlight 简单绑定/依赖属性

发布于 2024-10-27 18:54:41 字数 501 浏览 2 评论 0原文

我刚刚开始在 Silverlight 中进行开发,并且我有一个日历控件,可以显示每天的详细信息。

日历中的文本保存在许多文本块中,对于某些浏览器来说,文本大小可能太大,所以我想在“用户控件”上有一个滑块控件,允许用户调整字体大小。

我正在通过 C# 代码构建日历,所以我的问题是..“连接”它的最佳方法是什么。我猜这将是这些选项之一。

  1. 将事件添加到 ValueChanged 的​​滑块控件,然后迭代所有 TextBlock,将字体大小设置为新大小。这看起来很冗长。

  2. 也许使用附加到每个 TextBlock 的“样式”,然后只需更改“样式”的字体大小..?也许?

  3. 使用“绑定”& “附属财产”。我已经研究过这一点,这似乎是实现这一点的方法,但我找不到将值从一个控件传递到多个其他控件的示例。也许我遗漏了一些东西。

我可以很轻松地执行选项 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.

  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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无人接听 2024-11-03 18:54:41

解决这个问题的一种方法是不使用固定大小,而是根据其内容调整所有内容的大小。这样,当选择更大的字体大小时,控件将变得更大。就像文本块一样。

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.

我不会写诗 2024-11-03 18:54:41

实际上,我现在已经使用我很满意的选项 3 完成了这项工作,它非常简单,但似乎很少有关于它的文档(也许我正在寻找错误的东西)。

就像添加几行一样简单......

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

对于我想要应用 FontSlider 的“值”的每个控件......我这样做......

        MyTextBlock.SetBinding(TextBlock.FontSizeProperty,bind);

简单。

干杯
富有的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文