Customising the RecentDocumentMenu

Ribbon for WPF Forum

Posted 4 years ago by Ed
Version: 20.1.0
Avatar

I am trying to customise the RecentDocumentMenu control.

From my account I have downloaded the default XAML styles. Including, then editing the Menu.xaml does achieve what I want. However having such a large amount of Actipro source code in our codebase is something I'd like to avoid for future maintainance reasons.

I have been trying to modify the PART_Button named Grid element within the LargeRecentDocumentButtonStyle style.

I have tried the following from within a derrived class of RecentDocumentMenu:

public override void OnApplyTemplate()
{
base.OnApplyTemplate();

var grid1 = this.FindName("PART_Button");
var grid2 = this.GetTemplateChild("PART_Button");

var grid3 = base.FindName("PART_Button");
var grid4 = base.GetTemplateChild("PART_Button");

var grid5 = this.Template.FindName("PART_Button", this);
var grid6 = base.Template.FindName("PART_Button", this);

var grid7 = LogicalTreeHelper.FindLogicalNode(this, "PART_Button");

var grid8 = GetTemplateChild("PART_Button");

I have tried the following from within the containing view:

private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e)
{
var control = sender as RecentDocumentMenuCustomised;
var grid0 = control?.FindName("PART_Button");
var grid00 = control?.Template.FindName("PART_Button", control);

var grid1 = this.FindName("PART_Button");
var grid2 = this.GetTemplateChild("PART_Button");

var grid3 = base.FindName("PART_Button");
var grid4 = base.GetTemplateChild("PART_Button");

var grid5 = this.Template.FindName("PART_Button", this);
var grid6 = base.Template.FindName("PART_Button", this);

var grid7 = LogicalTreeHelper.FindLogicalNode(this, "PART_Button");

var grid8 = GetTemplateChild("PART_Button");

All with no success, every gridX result is null.

Could you tell me the best way to proceed?

Comments (9)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Edward,

First may I ask what exactly you are trying to change in the template?  There might be an easier way to do it.


Actipro Software Support

Posted 4 years ago by Ed
Avatar

The changes I've made are:

  • On the PART_Button Grid set Margin="0,2"
  • Changed the Label TextBlock Margin="0,2" FontWeight="Medium"
  • Changed the Description TextBlock FontStyle="Italic"
  • Added a 3rd column: <ColumnDefinition Width="Auto" /> to the grid.
  • Used this column to display the LastOpenedDateTime of the IDocumentReference formatted with a custom StringFormat and Opacity

[Modified 4 years ago]

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Edward,

Oh were you able to to make the changes already then?


Actipro Software Support

Posted 4 years ago by Ed
Avatar

I've made the changes to the Actipro Styles\Menu.xaml file which I have downloaded and included in my project as part of a merged dictionary.

But I'd prefer to make the changes in my xaml or code behind by targeting the PART_Button section. Without having to include the whole Styles\Menu.xaml file.

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

I'd probably recommend searching the visual tree instead of the ways you tried.  We have a VisualTreeHelperExtended class that has various methods for walking the visual tree.  Maybe you can use that to find the Grid with name "PART_Button" and then alter it and its visual children.


Actipro Software Support

Posted 4 years ago by Ed
Avatar

Would that search using VisualTreeHelperExtended be done inside the overridden OnApplyTemplate() method of my extended RecentDocumentMenu class?

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Yes, the visual tree should be established at that point.


Actipro Software Support

Posted 4 years ago by Ed
Avatar

This is my Live Visual Tree  - showing the CustomRecentDocumentMenu highlighted, the target PART_Button grid can be seen at the bottom
My Live Visual Tree

However my attempts with VisualTreeHelperExtended, all result in 0 or null.
VisualTreeHelperExtended results

Using a recursive search down the tree, the ItemsPresenter returns 0 children when queried, which prevents deeper searching.

Do I need to do something special to get the children of an ItemsPresenter and presumably a ContentPresenter?

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Edward,

VisualTreeHelperExtended is just calling the low-level VisualTreeHelper methods and directly interacting with the visual tree as it is.  If that is not showing any visual children for the ItemsPresenter, then perhaps the visual tree below it hasn't yet been constructed at that time?  It's odd the the Live Visual Tree would see it though.  But perhaps that tool window forces item generation and visual tree realization somehow?


Actipro Software Support

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.