I am trying to bind my rad chart title to a string in view model.
<telerik:ChartDefaultView.ChartTitle>
<telerik:ChartTitle Content= "{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type views:PlotView}},Path=DataContext.ChartTitle}" HorizontalAlignment="Center"/>
</telerik:ChartDefaultView.ChartTitle>
But it is not getting binded niether i am getting any error.
Please help.....
9 Answers, 1 is accepted
Unfortunately, there is a problem with title content databinding. Please, find attached a small example with a suggestion for a workaround.
Regards,
Ves
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Hi rooma,
I just spent way, way too long trying to sort this out. I am incredulous that a WPF product has an issue with binding to the view model and it remains unfixed. Here is what I did to get around the problem after hours and hours of trying figure out what was wrong in my xaml. It really never occurred to me that such basic functionality could be not working.
I subscribed to the DataBound event to wire up my ChartTitle:
<telerik:RadChart x:Name="scatterChart" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DataBound="scatterChart_DataBound">
I gave a name to my ChartTitle
<telerik:ChartDefaultView.ChartTitle>
<telerik:ChartTitle Content=""
x:Name="title"
HorizontalAlignment="Center"
Background="White"
Foreground="Black"
Visibility="Visible">
</telerik:ChartTitle>
</telerik:ChartDefaultView.ChartTitle>
And I added the event handler in my code behind
private void scatterChart_DataBound(object sender, Telerik.Windows.Controls.Charting.ChartDataBoundEventArgs e)
{
this.title.Content = ((ScatterChartViewModel)this.DataContext).ChartTitle;
}
I have a hard time grasping how this could not be corrected ASAP... it is just such basic functionality. This is a WPF product with a main GUI element that is not bindable to the view model in the xaml. Outrageous! It is not right!
Hope this helps.
Regards
I agree, we are assessing the Telerik WPF chart controls for a new commercial application and this sort of issue is a problem when considering the suite.
Can you indicate if a defect has been logged against this issue and if there is a fix available?
Thanks
EDIT (Work around using dependency property that provides dynamic binding -- which above two solutions do not provide)
I created a new class inheriting from RadChart:
class NavitasRadChart
:RadChart
{
public static readonly DependencyProperty ChartTitleProperty =
DependencyProperty.Register(
"ChartTitle",
typeof(string),
typeof(NavitasRadChart),
new PropertyMetadata(string.Empty, OnChartTitleChanged));
private static void OnChartTitleChanged(DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var chart = dependencyObject as NavitasRadChart;
if (chart == null) return;
chart.Refresh();
}
public string ChartTitle
{
get { return (string) GetValue(ChartTitleProperty); }
set { SetValue(ChartTitleProperty, value); }
}
private void Refresh()
{
DefaultView.ChartTitle.Content = ChartTitle;
}
}
So it contains a new 'ChartTitle' dependency property; when the property is changed it executes the new Refresh method that looks after the title content.
The XAML in the view can use a binding expression, so if the model changes the title also changes:
<core:NavitasRadChart x:Name="radChart"
...
ChartTitle="{Binding Path=ChartTitleCaption}"
>
...
</core:NavitasRadChart>
The 'core' namespace refers to the location of the new class, in my case:
xmlns:core="clr-namespace:Navitas.Client.Core"
It is also surprising that binding does not seem to be possible custom lines or marked zones. I was further surprised there seems to be no way to bind a collection of ranges. It seems reasonable to expect more than one range.
The issues you are observing are caused by the difference between objects used for configuration and visual objects that are added to the visual tree at run time. We have identified this problem and we are taking actions to prevent such problems in our new charting solution - the RadChartView. In the chart view we are using only visual objects that work well with bindings.
Please excuse us for the caused inconvenience!
Yavor
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Regards
Custom lines and marked zones are currently under development and will be available with the Q3 release. Range series are also planned for the upcoming releases.
You can check this demo here that demonstrates how you can combine series. You can also combine series of different types using the same technique.
Yavor
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>