Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9106883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:26:32+00:00 2026-06-17T02:26:32+00:00

Let’s say I have a property on a class that needs to be rendered

  • 0

Let’s say I have a property on a class that needs to be rendered using a Hyperlink control. The hyperlink is to be bound to a command on the view model such that clicking on it triggers some action. Something like this:

<Style x:Key="HyperlinkStyle" TargetType="{x:Type igDP:CellValuePresenter}">
   <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                    <Border BorderBrush="{StaticResource DataGridCellOuterBorder}" BorderThickness="1,0,0,0"  >
                        <TextBlock Margin="5">
                                <Hyperlink                                      
                                    Command="{Binding ElementName=dataGrid, Path=DataContext.Commands[GetSolutionSummaryCmd], Mode=OneTime}"
                                    CommandParameter="{Binding Path=(igDP:DataRecord.DataItem), Mode=OneTime}">
                                    <TextBlock Text="{TemplateBinding Value}"/>                                                                      
                                </Hyperlink>                                                                                
                            </TextBlock>
                    </Border>                 
                </ControlTemplate>
            </Setter.Value>
        </Setter>       
    </Style>

How do I ensure that when data items are removed from the grid, the binding between dataGrid.DataContext.Command[GetSolutionSummaryCmd], an implementation of ICommand, and each data record with a hyperlink column is destroyed, so data item can be garbage collected? Otherwise, I see a potential for memory leaking here.

Also, GetSolutionSummaryCmd is an instance of RelayCommand implemented like this:

public class RelayCommand  : ICommand
{
    readonly protected Predicate<object> _canExecute;
    readonly protected Action<object> _execute;

    public RelayCommand(Predicate<object> canExecute, Action<object> execute)
        : this(canExecute, execute, true)
    {
    }

    public RelayCommand(Predicate<object> canExecute, Action<object> execute, bool isCommandAllowed)
    {
        _canExecute = canExecute;
        _execute = execute;
        IsAllowed = isCommandAllowed;
    }

    public void RaiseCanExecuteChanged()
    {
        if (this.CanExecuteChanged != null)
            this.CanExecuteChanged(this, EventArgs.Empty);
    }

    #region ICommand Members

    public virtual bool CanExecute(object parameter)
    {
        return _canExecute(parameter);
    }

    public event EventHandler CanExecuteChanged;

    public virtual void Execute(object parameter)
    {
        _execute(parameter);
    }    

    #endregion 
}

In contrast to this, I need to be able to raise CanExecuteChanged.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:26:33+00:00Added an answer on June 17, 2026 at 2:26 am

    I used the suggestions here to implement a solution for this problem. Leak was definitely being caused by hyperlink elements used in the above Style. ANTS profiler indicated this with a positive instance count for System.Windows.EffectiveValueEntry[] between memory snapshots. And when I look at the object reference graph for this class, there was always a reference to a hyperlink instance within the chain.

    Underlying data was changed so that hyperlinks can always be executed when clicked. This means that CanExecuteChanged event of ICommand does not have to be raised allowing me to define some kind of NoReferenceRelayCommand class like this:

        public class NoReferenceRelayCommand : ICommand
        {
            protected readonly Action<object> _execute;
    
            public NoReferenceRelayCommand(Action<object> execute)
            {
                Guard.ThrowIfArgumentIsNull(execute);
                _execute = execute;
            }
    
            #region ICommand Members
    
            public bool CanExecute(object parameter)
            {
                return true;
            }
    
            public event EventHandler CanExecuteChanged
            {
                add { }
                remove { }
            }
    
            public void Execute(object parameter)
            {
                _execute(parameter);
            }
    
            #endregion
        }
    

    Profiling solution over 10 hours shows that instance number of System.Windows.EffectiveValueEntry does not increase.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me explain best with an example. Say you have node class that can
Let's say I have one class User, and it has a property of type
Let's say you have a class library project that has any number of supplemental
Let's say I have an abstract parent class called shape, and that there are
Let say I have my view that I use it as a toggle button.
Let's say that I have classes like this: public class Parent { public int
Let's say you have a class, with certain properties, and that you tried your
Let's say I have the following classes that I want to construct using Ninject,
Let's say that I have a SQLite database that I create in a separate
Let's say I have two text files that I need to extract data out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.