简体   繁体   English

访问staticResource中的属性

[英]Accessing property in a staticResource

I am trying to use a property of a resource defined in xaml like this: 我正在尝试使用在xaml中定义的资源的属性,如下所示:

<Window.Resources>
    <map:TileLayer x:Key="OpenStreetMap" SourceName="OpenStreetMap"
                   Description="Maps © [OpenStreetMap Contributors](http://www.openstreetmap.org/copyright)"
                   TileSource="http://{c}.tile.openstreetmap.org/{z}/{x}/{y}.png"
                   MaxZoomLevel="14"/>

and then use the Description property to set Text of a TextBlock. 然后使用Description属性设置TextBlock的Text I have tried this but it does not work. 我已经尝试过了,但是没有用。

<TextBlock Text="{Binding Source={StaticResource OpenStreetMap.Description}}"/>
<TextBlock Text="{StaticResource OpenStreetMap.Description}"/>

How can I access the property in a resource defined in xaml? 如何在xaml中定义的资源中访问属性?

This way: 这条路:

<TextBlock Text="{Binding Source={StaticResource OpenStreetMap}, Path=Description}"/>

Or shorter: 或更短:

<TextBlock Text="{Binding Description, Source={StaticResource OpenStreetMap}}"/>

Note that the Description property contains markdown text. 请注意, Description属性包含降价文本。 You could use the HyperlinkText helper class like this: 您可以使用HyperlinkText帮助器类,如下所示:

<TextBlock map:HyperlinkText.InlinesSource="{Binding Description,
                                             Source={StaticResource OpenStreetMap}}"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM