Bug 38146 - Binding system ignore 2nd command on custom element
Summary: Binding system ignore 2nd command on custom element
Status: RESOLVED INVALID
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-28 19:36 UTC by Erik Renaud
Modified: 2016-10-21 15:13 UTC (History)
3 users (show)

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

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 INVALID

Description Erik Renaud 2016-01-28 19:36:01 UTC
Very weird...
I have a custom control that has two dependency properties of type Command. Only one gets binded the other is always null. My workaround is to invoke the command manually via the bindingcontext manually.

Here is my xaml:
    <ListView x:Name="TaskListView" IsVisible="{Binding IsListNotEmpty}" ItemsSource="{Binding Groups}" SeparatorVisibility="Default"
            IsGroupingEnabled="True" GroupDisplayBinding="{Binding Name}" ItemTapped="OnItemTapped" ItemSelected="OnItemSelected" BackgroundColor="{extensions:Color Background}">
    <ListView.GroupHeaderTemplate>
      <DataTemplate>
        <ViewCell>
          <customControls:ListViewTodoHeader Group="{Binding Group}" SelectCommand="{Binding Select}" AddCommand="{Binding AddTask}" Padding="0, 0, 0, 0"/>
        </ViewCell>
      </DataTemplate>
    </ListView.GroupHeaderTemplate>

In the ListViewTodoHeader, AddCommand is always null ! I have another instance where the same behavior happens with only one command is binded (n the select command).

Here the bindingcontextt:
public class GroupItem {
            public Command Select { get; set; }
            public Command AddTask { get; set; }
            public GroupItem()
            {
                Select = new Command(() =>
                {
                });
                AddTask = new Command(() =>
                {
                });
            }
}


And here is the code in the custom control:
        public readonly static BindableProperty SelectCommandProperty = BindableProperty.Create("SelectCommand", typeof(Command), typeof(ListViewHeaderBase), null, BindingMode.OneWay, null, null);
        public readonly static BindableProperty SelectCommandParameterProperty = BindableProperty.Create("SelectCommandParameter", typeof(string), typeof(ListViewHeaderBase), "", BindingMode.OneWay, null, null);
        public readonly static BindableProperty AddCommmandProperty = BindableProperty.Create("AddCommand", typeof(Command), typeof(ListViewHeaderBase), null, BindingMode.OneWay, null, AddCommandChanged);

        public Command SelectCommand
        {
            get { return (Command)GetValue(SelectCommandProperty); }
            set { SetValue(SelectCommandProperty, value); }
        }

        public string SelectCommandParameter
        {
            get { return (string)GetValue(SelectCommandParameterProperty); }
            set { SetValue(SelectCommandParameterProperty, value); }
        }

        public Command AddCommand
        {
            get { return (Command)GetValue(AddCommmandProperty); }
            set { SetValue(AddCommmandProperty, value); }
        }


In the custom control, I need to implement the following code for things to work:
                    if (AddCommand != null && AddCommand.CanExecute(null)) AddCommand.Execute(null);

                    //temporary hack because addcommand doesnt bind correctly
                    var x = this.BindingContext;
                    var y = x as ViewModels.Tabs.TodayVM.Group;
                    if (y.AddTask != null && y.AddTask.CanExecute(null)) y.AddTask.Execute(null);


AddCommand is ALWAYS null. yet SelectedCommand works fine.

When I examine base.Bindingcollection, there is no binding setup for AddCommand. Even if I change it's name (either in the control or in the bindingcontext , it doesn't work...
Comment 1 Erik Renaud 2016-02-09 20:46:39 UTC
Please contact me erik.renaud@modelon.net to receive the url to the project on OneDrive.
Comment 2 Jason Smith [MSFT] 2016-02-10 18:51:12 UTC
Are you using XamlC? Please email the project to jason@xamarin.com if you cant upload here.
Comment 3 Erik Renaud 2016-08-10 16:35:23 UTC
Just retested with the latest version, still have the problem - it's becoming a problem because we can't generalize controls as they need dependencies on the viewmodels...
Comment 4 Erik Renaud 2016-10-18 00:32:17 UTC
Well, this still isn`t fixed in the latest stable version.

In the latest pre (2.3.3.163-pre3), i get xamlc compile errors that it cannot find the dependency properties on my custom controls. 

What is funny is that the custom control has 3 dependency properties, and the error only shows up for the ones called "AddCommmand" and "DeleteCommand".

1>C:\Users\erikr\Source\Repos\DayTickler-Git\src\DayTickler\DayTickler.Views.Tabs.TodoPage.xaml(20,103): error : Position 20:103. No property, bindable property, or event found for 'AddCommand'
1>C:\Users\erikr\Source\Repos\DayTickler-Git\src\DayTickler\DayTickler.Views.Groups.DetailPage.xaml(12,57): error : Position 12:57. No property, bindable property, or event found for 'DeleteCommand'
1>C:\Users\erikr\Source\Repos\DayTickler-Git\src\DayTickler\DayTickler.Views.ToDosAndItems.DetailToDoPage.xaml(17,59): error : Position 17:59. No property, bindable property, or event found for 'DeleteCommand'
1>C:\Users\erikr\Source\Repos\DayTickler-Git\src\DayTickler\DayTickler.Views.ToDosAndItems.DetailWorkItemPage.xaml(12,64): error : Position 12:64. No property, bindable property, or event found for 'DeleteCommand'
1>C:\Users\erikr\Source\Repos\DayTickler-Git\src\DayTickler\DayTickler.Views.ToDosAndItems.DetailEventItemPage.xaml(12,66): error : Position 12:66. No property, bindable property, or event found for 'DeleteCommand'

renaming the dependency property doesn`t fix the problem for some reason...
Comment 5 Erik Renaud 2016-10-21 15:13:49 UTC
a typo in my code example... the latest XF made it visible à compile time or at runtime via an exception instead of letting it through.