Silverlight:多次引用同一元素而没有冗余?

发布于 2024-10-01 15:37:27 字数 665 浏览 2 评论 0原文

我正在构建一个 Silverlight Windows Phone 7 应用程序。我有以下元素:

<TextBox x:Name="DownloadFailed"
         Text="MySite.com could not be reached at this time. Do you have a network connection? &#xd;&#xa;&#xd;&#xa;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 技术交流群。

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

发布评论

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

评论(1

此岸叶落 2024-10-08 15:37:27

定义它

public static void ShowMessage(string message)
{
    Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show(message));
}

我在我的应用程序中实现此要求的一种方法是在静态 Helper 类中 。然后我将其用作 -

Helper.ShowMessage("Error Loading Data from remote service. Please try again later.");

您可以考虑构建一个包装 TextBlock 的控件(您的示例代码使用 TextBox,要显示静态文本,您可以使用 TextBlock< /code>) 并使用上述方法调用控件。

HTH,indyfromoz

One way I have implemented this requirement in my apps to define this -

public static void ShowMessage(string message)
{
    Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show(message));
}

in a static Helper class. I then use it as -

Helper.ShowMessage("Error Loading Data from remote service. Please try again later.");

You may consider building a control that wraps the TextBlock (Your sample code uses TextBox, to display static text, you can use TextBlock) and invoke the control using the method above.

HTH, indyfromoz

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