访问staticResource中的属性

qny*_*nyz 1 c# wpf xaml

我试图使用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"/>
Run Code Online (Sandbox Code Playgroud)

然后使用Description属性设置TextBlock的Text.我试过这个,但它不起作用.

<TextBlock Text="{Binding Source={StaticResource OpenStreetMap.Description}}"/>
<TextBlock Text="{StaticResource OpenStreetMap.Description}"/>
Run Code Online (Sandbox Code Playgroud)

如何在xaml中定义的资源中访问该属性?

Cle*_*ens 5

这条路:

<TextBlock Text="{Binding Source={StaticResource OpenStreetMap}, Path=Description}"/>
Run Code Online (Sandbox Code Playgroud)

或更短:

<TextBlock Text="{Binding Description, Source={StaticResource OpenStreetMap}}"/>
Run Code Online (Sandbox Code Playgroud)

请注意,该Description属性包含markdown文本.您可以HyperlinkText像这样使用辅助类:

<TextBlock map:HyperlinkText.InlinesSource="{Binding Description,
                                             Source={StaticResource OpenStreetMap}}"/>
Run Code Online (Sandbox Code Playgroud)