Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WPF Graph with GraphInteractionPalette hide Buttons

Solved!
Go to solution

Hello again,

 

how can we hide the Buttons from the GraphInteractionPalette?

Like set in the Graph, we just want "ZoomHorizontal, PanHorizontal" (with ZoomToFit)

GraphInteractionPalette_Buttons.png

 

 

        <ni:Graph x:Name="niGraph" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="1" Grid.RowSpan="2"
                       VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                       DataSource="{Binding Data}" FontWeight="Bold" FontSize="15"
                       local:GraphExtensions.AxesSource="{Binding Axes}" local:GraphExtensions.PlotsSource="{Binding Plots}"
                       niPrimitives:GraphConfiguration.ProcessAllAsynchronousUpdates="False"
                       niPrimitives:GraphConfiguration.UseBackgroundProcessing="True"
                       niPrimitives:GraphConfiguration.UseBackgroundRendering="False"
                       Interactions="ZoomHorizontal, PanHorizontal">
        </ni:Graph>
        <Expander Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" ExpandDirection="Left" IsExpanded="False"
                  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Header="{Binding}">
            <Expander.HeaderTemplate>
                <DataTemplate>
                    <Grid VerticalAlignment="{Binding VerticalAlignment, RelativeSource={RelativeSource AncestorType=ContentPresenter}, Mode=OneWayToSource}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <ni:GraphInteractionPalette Grid.Row="2" Graph="{Binding ElementName=niGraph}"
                                                    Orientation="Vertical" />
                        <!--<TextBlock Grid.Row="1" Text="T" />-->
                        <TextBlock Grid.Row="0" Text="Legende" HorizontalAlignment="Center">
                            <TextBlock.LayoutTransform>
                                <TransformGroup>
                                    <RotateTransform Angle="-90"/>
                                </TransformGroup>
                            </TextBlock.LayoutTransform>
                        </TextBlock>
                    </Grid>
                </DataTemplate>
            </Expander.HeaderTemplate>
            <Expander.Content>
                <ni:Legend ItemsSource="{Binding ElementName=niGraph, Path=Plots}"/>
            </Expander.Content>
        </Expander>

.NET-Framework 4.7.2 and 4.8

 

Measurement Studio 2019

Edition: Enterprise
Integration Version: 19.0.4.49154

 

0 Kudos
Message 1 of 4
(2,391 Views)
Solution
Accepted by topic author Weber.S

You can assign the InteractionsSource property with the specific interactions you want. In XAML:

<ni:GraphInteractionPalette ...>
    <ni:GraphInteractionPalette.InteractionsSource>
        <x:Array Type="ni:GraphInteraction">
            <x:Static Member="ni:GraphInteraction.PanHorizontal" />
            <x:Static Member="ni:GraphInteraction.ZoomHorizontal" />
            <x:Static Member="ni:GraphInteraction.ZoomToFit" />
        </x:Array>
    </ni:GraphInteractionPalette.InteractionsSource>
</ni:GraphInteractionPalette>
~ Paul H
0 Kudos
Message 2 of 4
(2,358 Views)
Solution
Accepted by topic author Weber.S

Hello Paul,

 

thanks for the answer!

 

But i get an NullReferenceException with your Example.

 

Stacktrace:

bei System.Xaml.Schema.XamlTypeInvoker.AddToCollection(Object instance, Object item)
bei MS.Internal.Xaml.Runtime.ClrObjectRuntime.Add(Object collection, XamlType collectionType, Object value, XamlType valueXamlType)

 

GraphInteractionPalette_Buttons_Error_01.png

 

 

<UserControl x:Class="CMO.Common.Controls.NI.Graph.GraphBindable"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ni="http://schemas.ni.com/controls/2009/xaml/presentation"
             xmlns:niPrimitives="http://schemas.ni.com/controls/2009/xaml/presentation/primitives"
             xmlns:niData="clr-namespace:CMO.Common.Controls.NI.Example"
             xmlns:local="clr-namespace:CMO.Common.Controls.NI.Graph"
             mc:Ignorable="d" 
             d:DataContext="{d:DesignInstance {x:Type niData:DataholderGraphWpf}, IsDesignTimeCreatable=True}"
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ni:GraphThumbnail x:Name="niThumb" Grid.Column="0" Grid.Row="0" GraphAdapter="{Binding ElementName=niGraph}" MaxHeight="50" Visibility="Collapsed" />

        <ni:Graph x:Name="niGraph" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="1" Grid.RowSpan="2"
                       VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                       DataSource="{Binding Data}" FontWeight="Bold" FontSize="15"
                       local:GraphExtensions.AxesSource="{Binding Axes}" local:GraphExtensions.PlotsSource="{Binding Plots}"
                       niPrimitives:GraphConfiguration.ProcessAllAsynchronousUpdates="False"
                       niPrimitives:GraphConfiguration.UseBackgroundProcessing="True"
                       niPrimitives:GraphConfiguration.UseBackgroundRendering="False"
                       Interactions="ZoomHorizontal, PanHorizontal">
        </ni:Graph>

        <Button x:Name="cmdShowThumb" Grid.Column="0" Grid.Row="1" Content="Show Thumb" Click="cmdShowThumb_Click"
                HorizontalAlignment="Left" VerticalAlignment="Top" />

        <Expander Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" ExpandDirection="Left" IsExpanded="False"
                  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Header="{Binding}">
            <Expander.HeaderTemplate>
                <DataTemplate>
                    <Grid VerticalAlignment="{Binding VerticalAlignment, RelativeSource={RelativeSource AncestorType=ContentPresenter}, Mode=OneWayToSource}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <ni:GraphInteractionPalette Grid.Row="2" Graph="{Binding ElementName=niGraph}"
                                                    Orientation="Vertical">
                            <ni:GraphInteractionPalette.InteractionsSource>
                                <x:Array Type="ni:GraphInteraction">
                                    <x:Static Member="ni:GraphInteraction.PanHorizontal" />
                                    <x:Static Member="ni:GraphInteraction.ZoomHorizontal" />
                                    <x:Static Member="ni:GraphInteraction.ZoomToFit" />
                                </x:Array>
                            </ni:GraphInteractionPalette.InteractionsSource>
                        </ni:GraphInteractionPalette>
                        <!--<TextBlock Grid.Row="1" Text="T" />-->
                        <TextBlock Grid.Row="0" Text="Legende" HorizontalAlignment="Center">
                            <TextBlock.LayoutTransform>
                                <TransformGroup>
                                    <RotateTransform Angle="-90"/>
                                </TransformGroup>
                            </TextBlock.LayoutTransform>
                        </TextBlock>
                    </Grid>
                </DataTemplate>
            </Expander.HeaderTemplate>
            <Expander.Content>
                <ni:Legend ItemsSource="{Binding ElementName=niGraph, Path=Plots}"/>
            </Expander.Content>
        </Expander>
        <CheckBox x:Name="chkRefresh" Grid.Row="2" Grid.Column="2" IsChecked="{Binding UseAutomaticRefresh}"
                  ToolTip="Automatische Aktualisierung aktiv?" HorizontalAlignment="Center" />
    </Grid>
</UserControl>

 

 

When i set the List in Code-behind and bind it to the Proprty it will work.

 

 

                        <ni:GraphInteractionPalette Grid.Row="2" Graph="{Binding ElementName=niGraph}"
                                                    Orientation="Vertical" InteractionsSource="{Binding GraphInteractions, ElementName=userControl}">
                            <!--<ni:GraphInteractionPalette.InteractionsSource>
                                <x:Array Type="ni:GraphInteraction">
                                    <x:Static Member="ni:GraphInteraction.PanHorizontal" />
                                    <x:Static Member="ni:GraphInteraction.ZoomHorizontal" />
                                    <x:Static Member="ni:GraphInteraction.ZoomToFit" />
                                </x:Array>
                            </ni:GraphInteractionPalette.InteractionsSource>-->
                        </ni:GraphInteractionPalette>

 

 

 

    public partial class GraphBindable : UserControl
    {
        public List<GraphInteraction> GraphInteractions { get; set; }
        public GraphBindable()
        {
            this.GraphInteractions = new List<GraphInteraction>();
            this.GraphInteractions.Add(GraphInteraction.PanHorizontal);
            this.GraphInteractions.Add(GraphInteraction.ZoomHorizontal);
            this.GraphInteractions.Add(GraphInteraction.ZoomToFit);
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                this.DataContext = new DataholderGraphEmpty();
            }
            try
            {
                InitializeComponent();
            }
            catch (Exception ex)
            {
                int i = 0;
            }
            this.niThumb.ViewportRelativeHorizontalRangeChanging += NiThumb_ViewportRelativeHorizontalRangeChanging;
        }
    }

 

 

Where comes the null-reference from?

 

 

And sorry for the late responce, i am on Holiday and just frequently check my business-mails.

 

Thanks!

 

Message 3 of 4
(2,338 Views)

Strange: using that XAML in either the main window or the user control works fine for me (I never see a null exception). Based on the exception message, I agree the XAML array is somehow the cause.

 

That said, the XAML-only approach was just to minimize the size of the example. Your workaround using a binding is more common, and very appropriate in this situation.

~ Paul H
Message 4 of 4
(2,331 Views)