Bug 58184 - x:Reference not being recognized when in a seperate ViewCell XAML file.
Summary: x:Reference not being recognized when in a seperate ViewCell XAML file.
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.5
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-07-17 09:38 UTC by gabsikarim
Modified: 2017-07-18 07:08 UTC (History)
2 users (show)

Tags: 2.3.5.256-pre6 xaml bindings
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 ANSWERED

Description gabsikarim 2017-07-17 09:38:16 UTC
Referencing a listview not working when its being referenced from within a seperate ViewCell
(Unhandled Exception: System.Exception: Can't resolve name on Element occurred)

CODE BELOW WORKS
<?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="ProjectHeyMobile.Views.Menupages.ConnectionPage">
    <ContentPage.Content>
        <ListView x:Name="ConnectionsListView"
                  HasUnevenRows="True" 
                  IsPullToRefreshEnabled="True" Refreshing="ConnectionsListView_Refreshing"
                  ItemsSource="{Binding Connections}"
                  SelectedItem="{Binding SelectedConnection, Mode=TwoWay}"
                  ItemSelected="ConnectionsListView_ItemSelected"
                  Style="{StaticResource listviewStyle}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                    <!--<view:ConnectionView BindingContext = "{Binding}"/>-->
                    <StackLayout HorizontalOptions="Fill" Padding="5" Orientation="Horizontal">
                        <Label Text="PIC" FontSize="Large" HorizontalOptions="Center" VerticalOptions="Center" />
                        <StackLayout HorizontalOptions="FillAndExpand" Orientation="Vertical" Padding="5">
                            <StackLayout HorizontalOptions="StartAndExpand" Orientation="Vertical">
                                <Label Text="{Binding Connections.Username}" FontSize="Medium" />
                                <Label Text="Last created message" FontSize="Default" />
                            </StackLayout>
                            <ProgressBar Progress="0.75" HorizontalOptions="Fill" />
                        </StackLayout>
                    </StackLayout>
                    <ViewCell.ContextActions>
                            <MenuItem 
                                Text="Hey. Features" 
                                Command="{Binding Path=BindingContext.ShowHeyFeaturesCommand, Source={x:Reference ConnectionsListView}}"
                                CommandParameter="{Binding}"/>
                            <MenuItem
                                Text="Block" 
                                Command="{Binding Path=BindingContext.BlockConnectionCommand, Source={x:Reference ConnectionsListView}}"
                                CommandParameter="{Binding}"/>
                            <MenuItem 
                                Text="Report" 
                                Command="{Binding Path=BindingContext.ReportConnectionCommand, Source={x:Reference ConnectionsListView}}"
                                CommandParameter="{Binding}"/>
                     </ViewCell.ContextActions>
                 </ViewCell>

                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </ContentPage.Content>
</ContentPage>

CODE BELOW DOESN'T WORK (Same as above, but with a ViewCell in a differen XAML file)
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:view="clr-namespace:ProjectHeyMobile.Views.Menupages"
             x:Class="ProjectHeyMobile.Views.Menupages.ConnectionPage">
    <ContentPage.Content>
        <ListView x:Name="ConnectionsListView"
                  HasUnevenRows="True" 
                  IsPullToRefreshEnabled="True" Refreshing="ConnectionsListView_Refreshing"
                  ItemsSource="{Binding Connections}"
                  SelectedItem="{Binding SelectedConnection, Mode=TwoWay}"
                  ItemSelected="ConnectionsListView_ItemSelected"
                  Style="{StaticResource listviewStyle}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <view:ConnectionView BindingContext = "{Binding}"/>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </ContentPage.Content>
</ContentPage>

<?xml version="1.0" encoding="UTF-8"?>
<ViewCell 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
   x:Class="ProjectHeyMobile.Views.Menupages.ConnectionView">
    <StackLayout HorizontalOptions="Fill" Padding="5" Orientation="Horizontal">
        <Label Text="PIC" FontSize="Large" HorizontalOptions="Center" VerticalOptions="Center" />
        <StackLayout HorizontalOptions="FillAndExpand" Orientation="Vertical" Padding="5">
            <StackLayout HorizontalOptions="StartAndExpand" Orientation="Vertical">
                <Label Text="{Binding Username}" FontSize="Medium" />
                <Label Text="Last created message" FontSize="Default" />
            </StackLayout>
            <ProgressBar Progress="0.75" HorizontalOptions="Fill" />
        </StackLayout>
    </StackLayout>
    <ViewCell.ContextActions>
            <MenuItem 
            Text="Hey. Features" 
            Command="{Binding Path=BindingContext.ShowHeyFeaturesCommand, Source={x:Reference ConnectionsListView}}"
            CommandParameter="{Binding}"/>
            <MenuItem
            Text="Block" 
            Command="{Binding Path=BindingContext.BlockConnectionCommand, Source={x:Reference ConnectionsListView}}"
            CommandParameter="{Binding}"/>
            <MenuItem 
            Text="Report" 
            Command="{Binding Path=BindingContext.ReportConnectionCommand, Source={x:Reference ConnectionsListView}}"
            CommandParameter="{Binding}"/>
    </ViewCell.ContextActions>
</ViewCell>
Comment 1 Stephane Delcroix 2017-07-18 07:08:21 UTC
from https://docs.microsoft.com/en-us/dotnet/framework/xaml-services/x-reference-markup-extension

  References an instance that is declared elsewhere in XAML markup. The reference   refers to an element's x:Name.

or, said otherwise: you can't x:Reference instances in other XAML files