Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is some code that appears to work for me to implement your own CommandColumnSeries, I stole a lot of it from the source for the ColumnSeries Sealed Class:</p> <pre><code>public class CommandColumnSeries : ColumnBarBaseSeries&lt;ColumnDataPoint&gt; { #region "ICommandSource" [Localizability(LocalizationCategory.NeverLocalize), Category("Action"), Bindable(true)] public ICommand Command { get { return (ICommand)base.GetValue(CommandProperty); } set { base.SetValue(CommandProperty, value); } } [Bindable(true), Category("Action"), Localizability(LocalizationCategory.NeverLocalize)] public object CommandParameter { get { return base.GetValue(CommandParameterProperty); } set { base.SetValue(CommandParameterProperty, value); } } [Category("Action"), Bindable(true)] public IInputElement CommandTarget { get { return (IInputElement)base.GetValue(CommandTargetProperty); } set { base.SetValue(CommandTargetProperty, value); } } public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register("CommandParameter", typeof(object), typeof(CommandColumnSeries), new FrameworkPropertyMetadata(null)); public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(CommandColumnSeries), new FrameworkPropertyMetadata(null)); public static readonly DependencyProperty CommandTargetProperty = DependencyProperty.Register("CommandTarget", typeof(IInputElement), typeof(CommandColumnSeries), new FrameworkPropertyMetadata(null)); #endregion #region public IRangeAxis DependentRangeAxis /// &lt;summary&gt; /// Gets or sets the dependent range axis. /// &lt;/summary&gt; public IRangeAxis DependentRangeAxis { get { return GetValue(DependentRangeAxisProperty) as IRangeAxis; } set { SetValue(DependentRangeAxisProperty, value); } } /// &lt;summary&gt; /// Identifies the DependentRangeAxis dependency property. /// &lt;/summary&gt; [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "This member is necessary because the base classes need to share this dependency property.")] public static readonly DependencyProperty DependentRangeAxisProperty = DependencyProperty.Register( "DependentRangeAxis", typeof(IRangeAxis), typeof(ColumnSeries), new PropertyMetadata(null, OnDependentRangeAxisPropertyChanged)); /// &lt;summary&gt; /// DependentRangeAxisProperty property changed handler. /// &lt;/summary&gt; /// &lt;param name="d"&gt;ColumnBarBaseSeries that changed its DependentRangeAxis.&lt;/param&gt; /// &lt;param name="e"&gt;Event arguments.&lt;/param&gt; private static void OnDependentRangeAxisPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { CommandColumnSeries source = (CommandColumnSeries)d; IRangeAxis newValue = (IRangeAxis)e.NewValue; source.OnDependentRangeAxisPropertyChanged(newValue); } /// &lt;summary&gt; /// DependentRangeAxisProperty property changed handler. /// &lt;/summary&gt; /// &lt;param name="newValue"&gt;New value.&lt;/param&gt; private void OnDependentRangeAxisPropertyChanged(IRangeAxis newValue) { this.InternalDependentAxis = (IAxis)newValue; } #endregion public IRangeAxis DependentRangeAxis #region public IAxis IndependentAxis /// &lt;summary&gt; /// Gets or sets the independent category axis. /// &lt;/summary&gt; public IAxis IndependentAxis { get { return GetValue(IndependentAxisProperty) as IAxis; } set { SetValue(IndependentAxisProperty, value); } } /// &lt;summary&gt; /// Identifies the IndependentAxis dependency property. /// &lt;/summary&gt; [SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "This member is necessary because the base classes need to share this dependency property.")] public static readonly DependencyProperty IndependentAxisProperty = DependencyProperty.Register( "IndependentAxis", typeof(IAxis), typeof(ColumnSeries), new PropertyMetadata(null, OnIndependentAxisPropertyChanged)); /// &lt;summary&gt; /// IndependentAxisProperty property changed handler. /// &lt;/summary&gt; /// &lt;param name="d"&gt;ColumnBarBaseSeries that changed its IndependentAxis.&lt;/param&gt; /// &lt;param name="e"&gt;Event arguments.&lt;/param&gt; private static void OnIndependentAxisPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { CommandColumnSeries source = (CommandColumnSeries)d; IAxis newValue = (IAxis)e.NewValue; source.OnIndependentAxisPropertyChanged(newValue); } /// &lt;summary&gt; /// IndependentAxisProperty property changed handler. /// &lt;/summary&gt; /// &lt;param name="newValue"&gt;New value.&lt;/param&gt; private void OnIndependentAxisPropertyChanged(IAxis newValue) { this.InternalIndependentAxis = (IAxis)newValue; } #endregion public IAxis IndependentAxis public CommandColumnSeries() { this.SelectionChanged += new SelectionChangedEventHandler(CommandColumnSeries_SelectionChanged); } private void CommandColumnSeries_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (Command != null) { RoutedCommand routedCommand = Command as RoutedCommand; CommandParameter = e.Source; if (routedCommand != null) { routedCommand.Execute(CommandParameter, CommandTarget); } else { Command.Execute(CommandParameter); } } } protected override void GetAxes(DataPoint firstDataPoint) { // Taken from the source of the ColumnSeries sealed class. GetAxes( firstDataPoint, (axis) =&gt; axis.Orientation == AxisOrientation.X, () =&gt; new CategoryAxis { Orientation = AxisOrientation.X }, (axis) =&gt; { IRangeAxis rangeAxis = axis as IRangeAxis; return rangeAxis != null &amp;&amp; rangeAxis.Origin != null &amp;&amp; axis.Orientation == AxisOrientation.Y; }, () =&gt; { IRangeAxis rangeAxis = CreateRangeAxisFromData(firstDataPoint.DependentValue); rangeAxis.Orientation = AxisOrientation.Y; if (rangeAxis == null || rangeAxis.Origin == null) { throw new InvalidOperationException("No Suitable Axes found for plotting range axis."); } DisplayAxis axis = rangeAxis as DisplayAxis; if (axis != null) { axis.ShowGridLines = true; } return rangeAxis; }); } protected override void UpdateDataPoint(DataPoint dataPoint) { // This code taken from the ColumnSeries sealed class. if (SeriesHost == null )//|| PlotArea == null) { return; } object category = dataPoint.ActualIndependentValue ?? (IndexOf&lt;DataPoint&gt;(this.ActiveDataPoints, dataPoint) + 1); Range&lt;UnitValue&gt; coordinateRange = GetCategoryRange(category); if (!coordinateRange.HasData) { return; } else if (coordinateRange.Maximum.Unit != Unit.Pixels || coordinateRange.Minimum.Unit != Unit.Pixels) { throw new InvalidOperationException("This Series Does Not Support Radial Axes"); } double minimum = (double)coordinateRange.Minimum.Value; double maximum = (double)coordinateRange.Maximum.Value; double plotAreaHeight = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Range.Maximum).Value.Value; IEnumerable&lt;CommandColumnSeries&gt; columnSeries = SeriesHost.Series.OfType&lt;CommandColumnSeries&gt;().Where(series =&gt; series.ActualIndependentAxis == ActualIndependentAxis); int numberOfSeries = columnSeries.Count(); double coordinateRangeWidth = (maximum - minimum); double segmentWidth = coordinateRangeWidth * 0.8; double columnWidth = segmentWidth / numberOfSeries; int seriesIndex = IndexOf&lt;CommandColumnSeries&gt;(columnSeries, this); double dataPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(ToDouble(dataPoint.ActualDependentValue)).Value.Value; double zeroPointY = ActualDependentRangeAxis.GetPlotAreaCoordinate(ActualDependentRangeAxis.Origin).Value.Value; double offset = seriesIndex * Math.Round(columnWidth) + coordinateRangeWidth * 0.1; double dataPointX = minimum + offset; if (GetIsDataPointGrouped(category)) { // Multiple DataPoints share this category; offset and overlap them appropriately IGrouping&lt;object, DataPoint&gt; categoryGrouping = GetDataPointGroup(category); int index = GroupIndexOf(categoryGrouping, dataPoint); dataPointX += (index * (columnWidth * 0.2)) / (categoryGrouping.Count() - 1); columnWidth *= 0.8; Canvas.SetZIndex(dataPoint, -index); } if (CanGraph(dataPointY) &amp;&amp; CanGraph(dataPointX) &amp;&amp; CanGraph(zeroPointY)) { double left = Math.Round(dataPointX); double width = Math.Round(columnWidth); double top = Math.Round(plotAreaHeight - Math.Max(dataPointY, zeroPointY) + 0.5); double bottom = Math.Round(plotAreaHeight - Math.Min(dataPointY, zeroPointY) + 0.5); double height = bottom - top + 1; Canvas.SetLeft(dataPoint, left); Canvas.SetTop(dataPoint, top); dataPoint.Width = width; dataPoint.Height = height; } } private static int IndexOf&lt;T&gt;(IEnumerable&lt;T&gt; collection, T target) { int i = 0; foreach (var obj in collection) { if (obj.Equals(target)) return i; i++; } return -1; } private static int GroupIndexOf(IGrouping&lt;object, DataPoint&gt; group, DataPoint point) { int i = 0; foreach (var pt in group) { if (pt == point) return i; i++; } return -1; } /// &lt;summary&gt; /// Returns a value indicating whether this value can be graphed on a /// linear axis. /// &lt;/summary&gt; /// &lt;param name="value"&gt;The value to evaluate.&lt;/param&gt; /// &lt;returns&gt;A value indicating whether this value can be graphed on a /// linear axis.&lt;/returns&gt; private static bool CanGraph(double value) { return !double.IsNaN(value) &amp;&amp; !double.IsNegativeInfinity(value) &amp;&amp; !double.IsPositiveInfinity(value) &amp;&amp; !double.IsInfinity(value); } /// &lt;summary&gt; /// Converts an object into a double. /// &lt;/summary&gt; /// &lt;param name="value"&gt;The value to convert to a double.&lt;/param&gt; /// &lt;returns&gt;The converted double value.&lt;/returns&gt; private static double ToDouble(object value) { return Convert.ToDouble(value, CultureInfo.InvariantCulture); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload