I'm looking for a way to display a range indicator in the label panel of the xamDataGrid.
I've tried tapping in to the LabelPanelStyle of the axis, which gives me access to the panel I need; however, when I attempt to databind properties in the LabelPanelStyle, I'm surprised to find that the datacontext for the panel style is not the same datacontext for the containing axis. Instead, it seems to be the datacontext for the containing xamDataChart.
In the attached project, the chart display is driven by an object that exposes a view model for the YAxis. The axis view model exposes a red gradient BackgroundBrush property that I would like to be used in the labelpanel background, and for example purposes the chart view model exposes a solid green brush as its BackgroundBrush property. The binding operation on the LabelPanelStyle setter appears to reference the data context for the chart, not the axis - when I run the attached example, the label panel is solid green, not a red gradient.
I realize I can fix this example easily by changing the LabelPanelStyle binding expressions to reference the YAxisViewModel.BackgroundBrush; however, in production the data is not this simple and there could be several axes that require this processing. I see no way to determine which label panel is associated with which axis...
Thoughts?
Hello,
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
If the above suggestion helped you solve your issue please verify the thread as answered so other users may take better advantage of it.
I have been looking into your enquiry and I assume that the DataContext of the LabelsPanels do not come from their axes, because the panels are actually higher in the visual tree. Meaning it has been decided to make the logical children to the XamDataChart so that they can be moved around the plotting area and at the same time the axes place lower in the visual tree so they used accordingly in the plotting area’s initialization.
Since there doesn’t seem to be any direct reference between the axes and the label panels I can only suggest you give up setting the LabelPanelStyle through xaml:
<!--<ig:NumericYAxis.LabelPanelStyle >
<Style >
<Setter Property="Control.Background" Value="{Binding BackgroundBrush}"/>
</Style>
</ig:NumericYAxis.LabelPanelStyle>-->
Instead I can suggest using another generic custom approach I came up with. Since you mentioned that you would have many axes can suggest you create an implicit Style that would apply to all of them:
<Style TargetType="{x:Type ig:NumericYAxis}">
<EventSetter Event="Loaded" Handler="NumericAxes_Loaded" />
and in the EventSetter’s loaded event handler you can use this code snippet, which will provide the necessary data context and the sam binding as you had used in xaml:
void NumericAxes_Loaded(object sender, RoutedEventArgs e)
{
Style panelstyle = new Style(typeof(VerticalAxisLabelPanel));
panelstyle.Setters.Add(new Setter(VerticalAxisLabelPanel.DataContextProperty, (sender as NumericYAxis).DataContext));
panelstyle.Setters.Add(new Setter(VerticalAxisLabelPanel.BackgroundProperty, new Binding("BackgroundBrush")));
(sender as NumericYAxis).LabelPanelStyle = panelstyle;
}
Please let me know if this suits your requirement. or have I misunderstood you in any way. Looking forward to hearing from you.