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 7952241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:48:02+00:00 2026-06-04T02:48:02+00:00

here, i am using mvvm .in that my partner use class CommandBindingExtension ,in that

  • 0

here, i am using mvvm .in that my partner use class CommandBindingExtension ,in that i can understand role of IProvideValueTarget and IServiceProvider.

[MarkupExtensionReturnType(typeof(ICommand))]
public class CommandBindingExtension : MarkupExtension
{
    public CommandBindingExtension(string commandName)
    {
        this.CommandName = commandName;
    }

    [ConstructorArgument("commandName")]
    public string CommandName { get; set; }

    private object targetObject;
    private object targetProperty;

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        IProvideValueTarget provideValueTarget = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
        if (provideValueTarget != null)
        {
            targetObject = provideValueTarget.TargetObject;
            targetProperty = provideValueTarget.TargetProperty;
        }

        if (!string.IsNullOrEmpty(CommandName))
        {
            // The serviceProvider is actually a ProvideValueServiceProvider, which has a private field "_context" of type ParserContext
            ParserContext parserContext = GetPrivateFieldValue<ParserContext>(serviceProvider, "_context");
            if (parserContext != null)
            {
                // A ParserContext has a private field "_rootElement", which returns the root element of the XAML file
                FrameworkElement rootElement = GetPrivateFieldValue<FrameworkElement>(parserContext, "_rootElement");
                if (rootElement != null)
                {
                    // Now we can retrieve the DataContext
                    object dataContext = rootElement.DataContext;

                    // The DataContext may not be set yet when the FrameworkElement is first created, and it may change afterwards,
                    // so we handle the DataContextChanged event to update the Command when needed
                    if (!dataContextChangeHandlerSet)
                    {
                        rootElement.DataContextChanged += new DependencyPropertyChangedEventHandler(rootElement_DataContextChanged);
                        dataContextChangeHandlerSet = true;
                    }

                    if (dataContext != null)
                    {
                        ICommand command = GetCommand(dataContext, CommandName);
                        if (command != null)
                            return command;
                    }
                }
            }
        }

        // The Command property of an InputBinding cannot be null, so we return a dummy extension instead
        return DummyCommand.Instance;
    }

plz explain what is the role of it.if u need whole class code than i will give it.

  • 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-04T02:48:03+00:00Added an answer on June 4, 2026 at 2:48 am

    IProvideValueTarget is one of the services the service provider can provide in this context. See MSDN for more info on those services.

    Authors of the types that support type converter and markup extension usages must often have contextual information about where a usage is located in the markup, or in surrounding object graph structure. Information might be needed so that the provided object is instantiated correctly or so that object references to existing objects in the object graph can be made. When using .NET Framework XAML Services, the context that might be required is exposed as a series of service interfaces.

    The services available for a markup extension or type converter implementation are communicated through the context parameters that are part of the signature of each virtual method. In every case, you have IServiceProvider implemented in the context, and can call IServiceProvider.GetService to request a service.

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

Sidebar

Related Questions

Here, I am using MVVM in WPF and I read that it contains poco.
I have a WPF application implemented using the MVVM framework that uses an ActiveX
I've been using the popular MVVM Light toolkit: here for creating my Windows Phone
Here is the problem. I am using MVVM on a WPF project and using
I am building a silverlight application using MVVM pattern but I don't understand what
I have a WPF/MVVM (using MVVM-Light) app setup with a ComboBox that is inside
I'm using a PasswordBox which exposes a dependency property such that I can bind
This question is an extension to the one raised here: Using factory_girl in Rails
EDIT: The plugin in question is located here . PHP beginner here using a
why are we using here 5 parameters for stringWithFormat : return [NSString stringWithFormat:NSLocalizedString(@LatLongFormat, @LatLongFormat),

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.