I am not sure if this part of it being beta or not, but it doesn't appear that the LeafTemplate is databound to an item in the ItemsSource. If I do this:
...the Icon or Name isn't displayed. It does appear the LeafTemplate does actually work though if I change those to hard-coded values.
Thoughts?
<
telerik:RadPivotMap
x:Name
=
"PivotMap"
ItemsSource
=
"{Binding ImageEntries}"
ValuePath
=
"Rating"
LabelPath
=
"Name"
>
<
telerik:RadPivotMap.LeafTemplate
>
<
DataTemplate
>
<
Grid
Background
=
"Aquamarine"
>
<
Image
Source
=
"{Binding Icon}"
/>
<
TextBlock
Text
=
"{Binding Name}"
VerticalAlignment
=
"Bottom"
HorizontalAlignment
=
"Right"
/>
</
Grid
>
</
DataTemplate
>
</
telerik:RadPivotMap.LeafTemplate
>
</
telerik:RadPivotMap
>
...the Icon or Name isn't displayed. It does appear the LeafTemplate does actually work though if I change those to hard-coded values.
Thoughts?
4 Answers, 1 is accepted
0
Peter
Top achievements
Rank 1
answered on 19 Jul 2011, 09:49 PM
Problem solved, it appears that LeafTemplate is actually databound to a HierarchicalData, so the item itself is actually an object property called DataItem. The following appears to be the correct implementation:
But that does raise another question... The HiearchicalData object doesn't have anything like a ActualHeight or ActualWidth property that would seem to be really useful in the DataTemplate. Is there anyway to get up a level to the RadTreeMapItem which does have that data?
<
telerik:RadPivotMap
x:Name
=
"PivotMap"
Grid.Column
=
"0"
ItemsSource
=
"{Binding ImageEntries}"
ValuePath
=
"Rating"
LayoutStrategy
=
"Squarified"
>
<
telerik:RadPivotMap.LeafTemplate
>
<
DataTemplate
>
<
Grid
Background
=
"Aquamarine"
>
<
Image
Source
=
"{Binding Path=DataItem.Icon}"
/>
<
TextBlock
Text
=
"{Binding Path=DataItem.Name}"
VerticalAlignment
=
"Bottom"
HorizontalAlignment
=
"Right"
/>
</
Grid
>
</
DataTemplate
>
</
telerik:RadPivotMap.LeafTemplate
>
</
telerik:RadPivotMap
>
But that does raise another question... The HiearchicalData object doesn't have anything like a ActualHeight or ActualWidth property that would seem to be really useful in the DataTemplate. Is there anyway to get up a level to the RadTreeMapItem which does have that data?
0
Hi Peter,
That's correct. Using Path=DataItem.PropName will give you access to the values in the underlying data item. If you need the RadTreeMapItem.ActualHeight and RadTreeMapItem.ActualWidth in order to stretch the grid to fill the entire item with the desired background, you can use a BrushColorizer instead:
Our developers are working on exposing a LeafItemStyle property, which will allow better control over the leaf items.
Best regards,
Ves
the Telerik team
That's correct. Using Path=DataItem.PropName will give you access to the values in the underlying data item. If you need the RadTreeMapItem.ActualHeight and RadTreeMapItem.ActualWidth in order to stretch the grid to fill the entire item with the desired background, you can use a BrushColorizer instead:
<
telerik:RadPivotMap.LeafMappings
>
<
telerik:BrushColorizer
Brush
=
"Aquamarine"
/>
</
telerik:RadPivotMap.LeafMappings
>
......
<
telerik:RadPivotMap.LeafTemplate
>
<
Grid
>
<
Image
Source
=
"{Binding Path=DataItem.Icon}"
/>
<
TextBlock
Text
=
"{Binding Path=DataItem.Name}"
VerticalAlignment
=
"Bottom"
HorizontalAlignment
=
"Right"
/>
</
Grid
>
</
telerik:RadPivotMap.LeafTemplate
>
Our developers are working on exposing a LeafItemStyle property, which will allow better control over the leaf items.
Best regards,
Ves
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
0
sam
Top achievements
Rank 1
answered on 25 Jul 2011, 11:29 AM
Hi can any one please send me some sample code for
"RadPivotMap for Silverlight" .
0
Peter
Top achievements
Rank 1
answered on 25 Jul 2011, 01:24 PM
I ended up using RadTreeMap instead because I was having trouble with styling RadPivotMap. But here is the relevant markup:
The TypeDefinition looks like this:
The databound object is MediaFileEx:
<
telerik:RadTreeMap
x:Name
=
"TreeMap"
Grid.Row
=
"0"
LayoutStrategy
=
"Squarified"
Cursor
=
"Hand"
>
<
telerik:RadTreeMap.TypeDefinitions
>
<
telerik:TypeDefinition
TargetTypeName
=
"MediaFileEx"
ValuePath
=
"AdjustedRating"
>
<
telerik:TypeDefinition.Mappings
>
<
local:ImageCustomMapping
/>
</
telerik:TypeDefinition.Mappings
>
</
telerik:TypeDefinition
>
</
telerik:RadTreeMap.TypeDefinitions
>
</
telerik:RadTreeMap
>
The TypeDefinition looks like this:
Imports Telerik.Windows.Controls
Imports Telerik.Windows.Controls.TreeMap
Imports System.Windows.Media.Imaging
Imports System.Windows.Data
Public Class ImageCustomMapping
Inherits CustomMapping
Protected Overrides Sub Apply(treemapItem As RadTreeMapItem, dataItem As Object)
Dim ie = DirectCast(dataItem, MediaFileEx)
Dim grid = treemapItem.ChildrenOfType(Of Grid).SingleOrDefault
If Not grid Is Nothing Then
grid.Background = New ImageBrush With {.ImageSource = ie.Icon, .Stretch = Stretch.Uniform, .AlignmentX = AlignmentX.Center, .AlignmentY = AlignmentY.Center}
Dim panel As New StackPanel With {.Orientation = Orientation.Horizontal, .HorizontalAlignment = HorizontalAlignment.Left}
Dim tagImage As New Image With {.DataContext = dataItem, .Width = 16, .Height = 16, .HorizontalAlignment = HorizontalAlignment.Left}
tagImage.SetBinding(Image.SourceProperty, New Binding("TagIcon"))
panel.Children.Add(tagImage)
grid.Children.Add(panel)
AddHandler treemapItem.MouseLeftButtonUp, AddressOf ie.MouseLeftButtonUp
Else
' last item ends up here
End If
End Sub
Protected Overrides Sub Clear(treemapItem As RadTreeMapItem, dataItem As Object)
treemapItem.ClearValue(RadTreeMapItem.BackgroundProperty)
End Sub
End Class
The databound object is MediaFileEx:
Imports System.ComponentModel
Imports System.Windows.Media.Imaging
Public Class MediaFileEx
Inherits BrowserWs.MediaFile
Implements INotifyPropertyChanged
Property MyParent As Page
Public ReadOnly Property Icon As BitmapImage
Get
Return New BitmapImage(New Uri(Uri))
End Get
End Property
Property ShouldAdjustRating As Boolean = True
Public ReadOnly Property AdjustedRating As Integer
Get
If ShouldAdjustRating Then
Return (MyParent.Adjustment + Rating)
Else
Return Rating
End If
End Get
End Property
Public Shadows Property Rating As Integer
Get
Return MyBase.Rating
End Get
Set(value As Integer)
MyBase.Rating = value
PropertyChangedHandler("Rating")
End Set
End Property
Public ReadOnly Property TagIcon As BitmapImage
Get
If Not Tags Is Nothing AndAlso Tags.Count > 0 Then
Return MyParent.MyParent.MyParent.TagIcon
Else
Return Nothing
End If
End Get
End Property
Public Property TagsAsString As String
Get
If Tags Is Nothing Then Return String.Empty
Return Join(Tags.ToArray, ", ")
End Get
Set(value As String)
If Tags Is Nothing Then Tags = New BrowserWs.ArrayOfString
Dim sep As String = IIf(InStr(value, ";") > 0, ";", ",")
Tags.Clear()
For Each v In Split(value, sep)
v = LCase(Trim(v))
If Len(v) > 0 AndAlso Not Tags.Contains(v) Then Tags.Add(v)
Next
PropertyChangedHandler("TagIcon")
End Set
End Property
Public Sub MouseLeftButtonUp(sender As Object, e As System.Windows.Input.MouseButtonEventArgs)
'Dim mapItem = DirectCast(sender, RadTreeMapItem)
'Dim hierarchy = DirectCast(mapItem.DataContext, HierarchicalData)
MyParent.MyParent.MyParent.Selection = Me
End Sub
Public Shadows Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Protected Sub PropertyChangedHandler(ByVal propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
Public Sub New(parent As Page, mediaFile As BrowserWs.MediaFile)
MyParent = parent
Me.Source = mediaFile.Source
Me.Name = mediaFile.Name
Me.Uri = mediaFile.Uri
Me.Size = mediaFile.Size
Me.Tags = mediaFile.Tags
Me.Rating = mediaFile.Rating
End Sub
Public Sub New(parent As Page)
MyParent = parent
End Sub
End Class