将数据嵌入 XAML 文件中

发布于 2024-12-08 08:27:04 字数 380 浏览 0 评论 0原文

我已经研究一个 WPF 控件几个星期了,它包含一个 XAML 绘制的地图,并且能够放大/缩小和平移地图。此外,它还包含一个转换器,可以将屏幕坐标转换为纬度/经度坐标,效果非常好,但是,转换器的工作原理是基于一些常量参数,这些参数在应用程序加载时应该可用。

现在,这些参数是通过非 XAML 映射文件(.dwg 文件)加载的,这需要我引用外部库,并且当应用程序首次加载时,文件的加载需要几秒钟的时间,这有点烦人。

我想将该信息作为常量存储在 XAML 控件的 C# 代码隐藏中,但是有没有办法将这些常量嵌入到 XAML 本身中?由于控件应尽可能通用,并且应支持我将来提供的所有映射(每个映射都有不同的参数),因此我希望代码从 XAML 文件中读取参数并在代码中使用它。

如果我的问题不清楚,请告诉我。

I've been working on a WPF control for a few weeks now that contains a XAML-drawn map and has the ability to zoom in / out and pan the map. Also, it contains a converter that converts screen coordinates to lat / long coordinates which works pretty nice, however, the converter works based on few constant parameters that should be available when the application gets loaded.

Right now, those parameters are loaded with the non-XAML map file (.dwg file) which requires me to have a reference to an external library and the loading of the file takes up a few seconds when the application is loading for the first time, which is kinda annoying.

I wanted to store that information as constants in my C# code-behind for the XAML control, however is there a way to embed those constants in the XAML itself? Since the control should be as generic as possible and should support all maps that I will give it in the future (each having different parameters) I want the code to read the parameters from the XAML file and use it in the code.

If I wasn't clear in my question please let me know.

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

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

发布评论

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

评论(1

我早已燃尽 2024-12-15 08:27:04

您可能需要查看这篇文章。它是关于 Silverlight 但它应该适用。这篇代码项目文章也可能有一定用处。

You may want to look at this article. It is about Silverlight but it should be applicable. This Code Project article may be of some use also.

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