Reputation: 469
I am trying to use a property of a resource defined in xaml like this:
<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. 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?
Upvotes: 1
Views: 1306
Reputation: 128146
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. You could use the HyperlinkText
helper class like this:
<TextBlock map:HyperlinkText.InlinesSource="{Binding Description,
Source={StaticResource OpenStreetMap}}"/>
Upvotes: 6