Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

wpf graph minor gridlines

Solved!
Go to solution

What happened to minro gridlines in WPF version? There is no such property, only for ticks. WinForms version had this as I remember

0 Kudos
Message 1 of 11
(7,970 Views)

Unfortunately, we did not have time to implement all of the features available in Windows Forms for the WPF controls. We do plan to add features like minor gridlines in future releases.


As a workaround, you can use a custom axis type like the mockup below:


    XAML
    <local:CustomAxis>
        <local:CustomAxis.MinorGridLines>
            <ni:GridLines Stroke="#50A0" />
        </local:CustomAxis.MinorGridLines>
    </local:CustomAxis>

    Code
    public sealed class CustomAxis : Axis<double> {
        public static readonly DependencyProperty MinorGridLinesProperty =
            DependencyProperty.Register(
            "MinorGridLines", typeof( GridLines ), typeof( CustomAxis ) );

        public GridLines MinorGridLines {
            get { return (GridLines)GetValue( MinorGridLinesProperty ); }
            set { SetValue( MinorGridLinesProperty, value ); }
        }

        private GridLinesRenderer<double> minorGridLinesRenderer;

        protected override void RegisterParent( IGraph parent ) {
            if( MinorGridLines.TryGetRenderer( GetDataMapper( ), true, true, out minorGridLinesRenderer ) ) {
                minorGridLinesRenderer.Subdivisions = new NotifyingCollection<double>( );
                minorGridLinesRenderer.AxisOrientation = Orientation;

                ((ISupportChildren)parent).AddDependentChild( minorGridLinesRenderer );
            }

            base.RegisterParent( parent );
        }

        protected override void UnregisterParent( IGraph parent ) {
            base.UnregisterParent( parent );

            if( minorGridLinesRenderer != null ) {
                ((ISupportChildren)parent).RemoveDependentChild( minorGridLinesRenderer );
                minorGridLinesRenderer = null;
            }
        }

        protected override NotifyingCollection<TData> Present<TData>( ScalePresenter presenter, IRangeDataMapper<TData> dataMapper, bool isRangeEditable ) {
            var majorDivisions = base.Present<TData>( presenter, dataMapper, isRangeEditable );
            if( minorGridLinesRenderer != null ) {
                var minorDivisions = (IEnumerable<double>)MinorDivisions.Mode.GetSubdivisions( dataMapper, majorDivisions );
                minorGridLinesRenderer.Subdivisions.ReplaceAll( minorDivisions );
            }

            return majorDivisions;
        }
    }

~ Paul H
0 Kudos
Message 2 of 11
(7,956 Views)

Hi, Paul!

 

Would you please try this axis with Log10 scale. It freezes for me...

 

What I do:

run app with Linear axis - minor lines are there

switch to Log10 axis - no minor lines

switch to Linear - freeze

0 Kudos
Message 3 of 11
(7,946 Views)

 

first time graph is switched to log mode, there are no lines

then i pan it, and lines are there but usually with delay (see picture)

0 Kudos
Message 4 of 11
(7,941 Views)

same happens in linear mode. not related to log...

 

just pan the graph and you'll see the delay

0 Kudos
Message 5 of 11
(7,938 Views)
Solution
Accepted by topic author eugenem

You are correct: I forgot that the major divisions is a notifying collection that can be monitored, which meant the minor divisions renderer was missing updates. I have attached an updated version of the custom axis mockup, moving updates to the minor divisions renderer into a collection changed handler.

~ Paul H
0 Kudos
Message 6 of 11
(7,926 Views)

thanks! seems to work now

0 Kudos
Message 7 of 11
(7,921 Views)

I can't hide these lines when needed. Tried both:

 

Snippet

                (ax as AxisWithMinorGridLines).MinorGridLines = null;
                //(ax as AxisWithMinorGridLines).MinorGridLines.Visibility = System.Windows.Visibility.Collapsed;
0 Kudos
Message 8 of 11
(7,065 Views)

Looking at CustomAxis.cs, all that should be needed is to add a property change callback to the dependency property registration. When the minor grid lines are set to null or hidden, you can remove the renderer (as in UnregisterParent), or just clear the Subdivisions collection; when it is assigned or visible, you can add the renderer (RegisterParent) or restore Subdivisions.

~ Paul H
0 Kudos
Message 9 of 11
(7,060 Views)

Thanks!

0 Kudos
Message 10 of 11
(7,024 Views)