Disable Export and Print in Flexviewer

Posted by: andreas.fischer on 9 September 2018, 6:21 pm EST

  • Posted 9 September 2018, 6:21 pm EST

    Hello there,

    we need to remove the "export" and "print" buttons from the flexviewer menu. I've seen no options via code or xaml to so.

    How can we achieve this?

    Best regards,
    Andreas
  • Replied 9 September 2018, 7:08 pm EST

    Addition: I also checked flexViewer.ToolMenuItems but those are read-only (why oh why?). That would be the solution I think, to get rid of the menuitems we don't want to. Plus I checked the styles in the according generic.xaml. No chance here either... just templatecontainers, since the items are set via binding from a source (hence ToolMenuItems I suspect).

    The only ugly way is to place a blocking view or graphic in top of the complete toolmenu or the buttons.


    EDIT: Ok, I found a hacky workaround. I inspected the UI Elements with the Live UI Debugger and found the menuItems.

    Following code works if someone else is interested:


    List<string> hiddenMenuItems = new List<string> { "Export", "Print" };
    ScrollContentPresenter sp = UIHelper.FindChild<ScrollContentPresenter>(flexViewer, "ScrollContentPresenter");
    List<ListViewItem> items = UIHelper.FindAllElementsInVisualTree<ListViewItem>(sp);

    foreach (ListViewItem item in items)
    {
    string toolMenuName = item.GetValue(AutomationProperties.NameProperty).ToString();

    if (!hiddenMenuItems.Contains(toolMenuName)) continue;
    item.IsEnabled = false;
    item.Visibility = Visibility.Collapsed;
    }



    Method FindChild can be found here: https://stackoverflow.com/questions/636383/how-can-i-find-wpf-controls-by-name-or-type/1759923#1759923

    Method FindAllChildElementsInVisualTree:

    public static List<T> FindAllElementsInVisualTree<T>(DependencyObject parentElement) where T : DependencyObject
    {
    var list = new List<T>();
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parentElement); i++)
    {
    var child = VisualTreeHelper.GetChild(parentElement, i);
    if (child is T)
    list.Add(child as T);
    list.AddRange(FindAllElementsInVisualTree<T>(child));
    }
    return list;
    }



    But - Please open up the possibility to change or disable menuItems in FlexViewer, thanks!
  • Replied 10 September 2018, 9:43 pm EST

    Hello Andreas,

    Thank you for sharing the workaround of hiding the menu-items at run time using VisualTreeHelper.
    However, for customizing the FlexViewer menu items, you may use flexViewer.ToolMenuItems and remove the item from this collection, which you want to remove, as following:
     var items = ((C1FlexViewer)sender).ToolMenuItems;
    for (int i = items.Count - 1; i >= 0; i--)
    {
    switch (items.Tool)
    {
    case FlexViewerTool.PageSettings:
    case FlexViewerTool.Parameters:
    items.RemoveAt(i);
    break;
    }
    }

    Also, I would suggest you to refer the PdfView product sample installed at [i]\Documents\ComponentOne Samples\UWP\C1.UWP.Document\CS\PdfView location.


    Thanks
    Ruchir
  • Replied 10 September 2018, 11:43 pm EST

    Hello Ruchir,

    thanks for the suggestion. I already looked into the ToolMenuItems Collection but found that it was read-only, so I didn't pursued that further.

    I tried your snippet, just a little thing was missing.

    Here's the now working code:

    ObservableCollection<ToolMenuItem> items = flexViewer.ToolMenuItems;
    for (int i = items.Count - 1; i >= 0; i--)
    {
    ToolMenuItem item = items[i];
    switch (item.Tool)
    {
    case FlexViewerTool.PageSettings:
    case FlexViewerTool.Export:
    case FlexViewerTool.Print:
    case FlexViewerTool.Parameters:
    items.RemoveAt(i);
    break;
    }
    }


    Can confirm, that this is working.
    Just as a little feature request... would be great to also be able to show/hide them right in xaml (ShowExportTool = false and so on)

    Thanks,
    Andreas
  • Replied 11 September 2018, 3:26 pm EST

    Hi Andreas,

    I knew that you were aware of ToolMenuItems collection, but the way you were trying to use it needed some tweaking. Hence a sample code snippet was shared.
    Also, for the request of being able to show/hide the menu items from XAML, I have forwarded it to concerned team [ID:342628] and it might be added in future releases if they find it feasible.

    Thanks,
    Ruchir
  • Marked as Answer

    Replied 11 September 2018, 4:12 pm EST

    Hello Andreas,

    As per the discussion with the team, the request for adding the same functionality in xaml would not be added to the control. So, I am sorry that to meet your requirement, you need to use the code-behind.

    Thanks,
    Ruchir
  • Replied 11 September 2018, 4:57 pm EST

    Thank you for this area. [สมัครเอเย่นต์tndbet](http://ufabet-group.com/) :AO
  • Replied 11 September 2018, 4:57 pm EST

    Thank you for this area สมัครเอเย่นต์omgbet :AO
  • Replied 11 September 2018, 5:54 pm EST

    Ruchir.Agarwal said:
    Hello Andreas,

    As per the discussion with the team, the request for adding the same functionality in xaml would not be added to the control. So, I am sorry that to meet your requirement, you need to use the code-behind.

    Thanks,
    Ruchir


    No problem. Many thanks for forwarding the request anyway.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels