Bug 37395 - Xamarin.Forms.Xaml.IProvideValueTarget.TargetProperty NotImplemented
Summary: Xamarin.Forms.Xaml.IProvideValueTarget.TargetProperty NotImplemented
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-04 22:06 UTC by Ahmed Alejo
Modified: 2017-03-13 08:49 UTC (History)
10 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
repro solution (402.64 KB, application/zip)
2016-06-24 23:20 UTC, Jimmy [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Ahmed Alejo 2016-01-04 22:06:20 UTC
Xamarin.Forms.Xaml.Internals.SimpleValueTargetProvider is too simple.

public class OnPlatformExtension : IMarkupExtension
{
    public object ProvideValue(IServiceProvider serviceProvider)
    {
        var valueTargetProvider = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));
            
        //This property access raises a NotImplementedException
        var _ = valueTargetProvider.TargetProperty;
        return null;;
    }
}
Comment 1 Parmendra Kumar 2016-01-13 16:15:06 UTC
@Ahmed

I have checked this issue and I am not sure how to reproduce this issue.
Could you please provide us some steps? so that I can reproduce this issue at my end.

Screencast: http://www.screencast.com/t/JGvwMrQl

Thanks.
Comment 2 adamm 2016-06-21 22:28:45 UTC
If we take a look at the code on Github, it is pretty clear what Ahmed was saying.

https://github.com/xamarin/Xamarin.Forms/blob/d1ab4e1ce8b77a6df1d9981db69eff156ee945a6/Xamarin.Forms.Xaml/XamlServiceProvider.cs

public XamlValueTargetProvider(object targetObject, 
                               INode node, 
                               HydratationContext context, 
                               object targetProperty)
{
	Context = context;
	Node = node;
	TargetObject = targetObject;
	TargetProperty = targetProperty;
}

INode Node { get; }

HydratationContext Context { get; }

public object TargetObject { get; }

public object TargetProperty
{
	get { throw new NotImplementedException(); }
	private set { }
}


There is a very clear Not Implemented Exception in the getter, making it fairly imposisble to use the TargetProperty of the IProvideValueTarget.
Comment 3 Ahmed Alejo 2016-06-22 15:24:17 UTC
This bug is (better, or if, not only) verifiable in xaml code. So i present a pseudo-working-example to reproduce the bug

    public class PropertyNameExtension : IMarkupExtension
    {
        public object ProvideValue(IServiceProvider serviceProvider)
        {
            var valueTargetProvider = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));
                
            //This property access raises a NotImplementedException
            var property = valueTargetProvider.TargetProperty;
            return $"{property}";
        }
    }

in xaml:

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage
        xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        x:Class="App22.Page1"
        xmlns:app22="clr-namespace:App22"
        
        <Label Text="{app22:PropertyName}"/><!-- The label should display the string "Text" but a NotImplementedException is raised instead-->
    <ContentPage>
Comment 4 Ahmed Alejo 2016-06-22 15:27:12 UTC
REOPENDED
Comment 6 Sam 2016-06-24 08:37:53 UTC
It is indeed very clear in the source code that there is NotImplementedException thrown. This feature is helpful for implementing a custom binding extension.
Comment 7 Jimmy [MSFT] 2016-06-24 23:20:54 UTC
Created attachment 16487 [details]
repro solution

I am able to reproduce the NotImplementedException and have attached a repro solution.

### Steps to Reproduce
1. Run any of the projects inside the repro solution


### Expected Results
The app will launch


### Actual Results
The app throws a NotImplementedException when trying to access TargetProperty


### Tested Info
Tested on Forms 2.3
Comment 8 Stephane Delcroix 2016-12-20 20:26:36 UTC
This is not really a bug, that was an implementation choice.

That being said, it is implemented right now.