02-26-2015 05:52 AM
Hi,
I have a ni:Legend object binded to the Plots of my Graph object. Which Property of my Plot should I set from the C# code to see it displayed in the Legend window?
<ni:Legend Name="MyLegend" ItemsSource="{Binding ElementName=MyGraph, Path=Plots}" /> <ni:Graph Name="MyGraph" DataSource="{Binding UpdateSourceTrigger=PropertyChanged}"> <ni:Graph.Plots> <ni:Plot/> </ni:Graph.Plots>
</ni:Graph>
MyGraph.Plots[0].??? = ???
Solved! Go to Solution.
02-26-2015 11:30 AM
By default, the data template used for plots in the legend displays the Label
property.
02-27-2015 12:23 AM
Thanks!
I am almost there now:
var MyLabel1 = new Label(); MyLabel1.Content = "Something"; MyGraph.Plots[0].Label = MyLabel1;
But what I get in the Label window is. System.Window.Controls.Label: Something
How do I get rid of the unwanted information, and display only the Content of the Label?
02-27-2015 10:24 AM
The legend uses a WPF ContentPresenter
to display the plot Label
property. In the case of UI elements, it appears that ContentPresenter
defaults to using the ToString
representation, instead of the element itself.
To display content like "Something"
, you will want to assign that content directly to the plot Label
property:
MyGraph.Plots[0].Label = "Something";
If you want to specifically show a WPF Label
content control in the legend, you can use the LabelTemplate
property:
<ni:Graph.Plots>
<ni:Plot>
<ni:Plot.LabelTemplate>
<DataTemplate>
<Label Content="{Binding}" />
</DataTemplate>
</ni:Plot.LabelTemplate>
</ni:Plot>
</ni:Graph.Plots>
03-02-2015 01:29 AM
That did the trick! Thank you!