LegendItem how can I add new binding attribute?

4 posts, 0 answers
  1. Alan
    Alan avatar
    3 posts
    Member since:
    Sep 2013

    Posted 06 Jun 2014 Link to this post

    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.
  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 10 Jun 2014 Link to this post

    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.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Alan
    Alan avatar
    3 posts
    Member since:
    Sep 2013

    Posted 10 Jun 2014 in reply to Petar Marchev Link to this post

    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
  5. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 11 Jun 2014 Link to this post

    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.
     
Back to Top