This is a migrated thread and some comments may be shown as answers.

LegendItem how can I add new binding attribute?

3 Answers 170 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 06 Jun 2014, 01:52 PM
I added a 2nd TextBlock to DataTemplate for my RadLegeng on my RadCartesianChart:

<telerik:RadLegend.ItemTemplate>
    <DataTemplate>
        <Border BorderThickness="0" BorderBrush="Transparent" Margin="10,2,5,0" Padding="0,4,0,0" >
            <Grid>
                <TextBlock Text="{Binding Percent}" Foreground="White" Margin="0,0,0,0" FontSize="13" FontWeight="Normal" Width="35" HorizontalAlignment="Right" VerticalAlignment="Center" />
                <TextBlock Text="{Binding Title}" Foreground="White" Margin="18,0,0,0" FontSize="13" FontWeight="Normal" HorizontalAlignment="Left" VerticalAlignment="Center" />
                <Path Width="auto" Height="auto" Stroke="White" StrokeThickness="1" Fill="{Binding MarkerFill}" HorizontalAlignment="Left" VerticalAlignment="Center">
                    <Path.Data>
                        <Binding Path="ActualMarkerGeometry" RelativeSource="{RelativeSource AncestorType=telerik:LegendItemControl}" />
                    </Path.Data>
                </Path>
            </Grid>
        </Border>
    </DataTemplate>
</telerik:RadLegend.ItemTemplate>
 
I would like to add custom attribute to bind (Percent) to said 2nd TextBlock through binding and with named declaration of LegendItems:

<telerik:RadLegend.Items>
    <telerik:LegendItemCollection>
        <telerik:LegendItem MarkerFill="#FFF0F8FF" MarkerStroke="White" Title="< 5" x:Name="rl_0to5s" />
        <telerik:LegendItem MarkerFill="#FF00B000" MarkerStroke="White" Title="6 - 10" x:Name="rl_6to10s" />
        <telerik:LegendItem MarkerFill="#FFFFFF00" MarkerStroke="White" Title="11 - 20" x:Name="rl_11to20s" />
        <telerik:LegendItem MarkerFill="#FFFFA83E" MarkerStroke="White" Title="21 - 30" x:Name="rl_21to30s" />
        <telerik:LegendItem MarkerFill="#FFFF2020" MarkerStroke="White" Title="31 >" x:Name="rl_31s" />
    </telerik:LegendItemCollection>
</telerik:RadLegend.Items>

Through searching, I wasn't sure how/if I can add on a new attribute to the LegendItem schema for the custom binding.

What am I missing? Any help or direction would be appreciated.

3 Answers, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 10 Jun 2014, 08:30 AM
Hi Alan,

I am unsure of your complete set up, from the code you sent, it seems that you are not binding the legend items, but instead you are manually creating them in XAML. Please let me know if this is not the case, because my response below is only applicable if you are manually creating the LegendItems and a different solution is required if the chart is creating the LegendItems.

You cannot a custom attribute the LegendItem as it is a regular class. However, you can tweak the items to show what you desire. One way is to use the Title property, set both the values in it, and use a converter to separate them in the template. Another option is to use the Presenter property. It is meant to contain a reference to the object it represents. Perhaps you can create a new class MyLegendItemInfo, which has the Title and Percent properties you need. Then you can set the Presenter property of the LegendItems to instances of this object and get the information in the template from it: <TextBlock Text="{Binding Presenter.Percent}". Let us know if this information suffices.

Another option is to simply set the Presenter to the Percent value you need to display, but note that this would be misusing the property, because this Percent value is not the only thing you need to present.

Regards,
Petar Marchev
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Alan
Top achievements
Rank 1
answered on 10 Jun 2014, 01:57 PM
Petar,

Thank you for responding. I am declaring the data template and the items in XAML.

I'm okay with going down the path of building a custom class utilizing Presenter.Percent method.

Additionally I am also curious how I could accomplish this with a converter through the Title.

Thank you again for your assistance. 

Alan
0
Petar Marchev
Telerik team
answered on 11 Jun 2014, 09:10 AM
Hi,

how I could accomplish this with a converter through the Title
Well, nothing too complex, just concatenate the two desired values in the title: Title="My title here ; 65%". Then you can create a converter that splits the string and returns the first part or the second part of the string. But you see that this is more or less misusing the Title property as it now holds two semantically different values, and not just a title. I hope this clears it up a bit.

Regards,
Petar Marchev
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
ChartView
Asked by
Alan
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Alan
Top achievements
Rank 1
Share this question
or