Hi!
For the PointLabelTemplate, you can define the template on the XAML. In my case, I want to configure the template based on user-specification. So I wrote the template in a string, and I use XamlReader.Load (String) in order to load the template. This works fine, except for one point. Silverlight does not allow events to be defined into the string. So my question is, is there a way for me to loop throught the labels that are created by the template, so I could attach the event in code ?
Here is a sample of the (VB) function I use to create a template, using some module _variables:
Private Function GetTemplate(ByVal Text As String, ByVal IsToolTip As Boolean) As DataTemplate
Dim Xaml As New StringBuilder
Xaml.AppendLine("<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:c1chart=""clr-namespace:C1.Silverlight.Chart;assembly=C1.Silverlight.Chart"" >") Xaml.AppendLine("<Border ") Xaml.AppendLine("c1chart:PlotElement.LabelAlignment=""" & _LabelAlignment & """ ") Xaml.AppendLine("Opacity=""" & _Opacity & """ Background=""White"" CornerRadius=""8"" ") Xaml.AppendLine("MouseEnter=""TextBlock_MouseEnter"" ") 'event don't work Xaml.AppendLine("MouseLeave=""TextBlock_MouseLeave"" ") 'event don't work If IsToolTip Then Xaml.AppendLine("BorderThickness=""0"" Padding=""4"">") Else Xaml.AppendLine("BorderBrush=""Black"" BorderThickness=""1"" Padding=""4"">") End If
Xaml.AppendLine("<TextBlock Text=""{Binding ") Xaml.AppendLine("Converter={StaticResource ResourceLabelConverter}, ") Xaml.AppendLine("ConverterParameter='" & Text.Replace("""", """""").Replace("'", "''") & "'}"" ") Xaml.AppendLine("Foreground=""Black"" FontSize=""8""/>") Xaml.AppendLine("</Border>") Xaml.AppendLine("</DataTemplate>")
Return CType(XamlReader.Load(Xaml.ToString), DataTemplate)
End Function
Hi,
As far as I remember the events can not be set in xaml that is loaded with XamlReader. I suppose you can create own class inherited from Border(or other framework element) that would handle the required events. Then the template with new class is loaded with XamlReader.
--Best regards,Alex