Silverlight:多次引用同一元素而没有冗余?
我正在构建一个 Silverlight Windows Phone 7 应用程序。我有以下元素:
<TextBox x:Name="DownloadFailed"
Text="MySite.com could not be reached at this time. Do you have a network connection? 

Try again in a few minutes."
BorderBrush="{x:Null}" Background="{x:Null}"
Foreground="{StaticResource PhoneDisabledBrush}" Margin="56,8,8,-8" TextWrapping="Wrap" />
如何定义一次并将其添加到我的应用程序中的多个页面?
我可以创建一个用户控件,但这对于这样一个具有一些属性的单个元素来说似乎有点矫枉过正。
我可以以某种方式使用 StaticResource
字典吗?还是只是为了属性?
我这样做的原因是因为我在许多不同的页面上都有内容,应用程序尝试从网络服务加载这些内容,但可能会失败。对于这样的控件/内容是否有常规的设计模式/封装?
I'm building a Silverlight Windows Phone 7 app. I have the following element:
<TextBox x:Name="DownloadFailed"
Text="MySite.com could not be reached at this time. Do you have a network connection?
Try again in a few minutes."
BorderBrush="{x:Null}" Background="{x:Null}"
Foreground="{StaticResource PhoneDisabledBrush}" Margin="56,8,8,-8" TextWrapping="Wrap" />
How can I define this once and add it to multiple pages in my app?
I could make a user control, but that seems like overkill for such a single element with a few properties.
Could I use the StaticResource
dictionary somehow? Or is that just for properties?
The reason I'm doing this is because I have content on a number of different pages that the app attempts to load from a web service, but may fail. Is there a conventional design pattern / encapsulation for such a control/content?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
定义它
我在我的应用程序中实现此要求的一种方法是在静态
Helper
类中 。然后我将其用作 -您可以考虑构建一个包装
TextBlock
的控件(您的示例代码使用TextBox
,要显示静态文本,您可以使用TextBlock< /code>) 并使用上述方法调用控件。
HTH,indyfromoz
One way I have implemented this requirement in my apps to define this -
in a static
Helper
class. I then use it as -You may consider building a control that wraps the
TextBlock
(Your sample code usesTextBox
, to display static text, you can useTextBlock
) and invoke the control using the method above.HTH, indyfromoz