i've a big Problem trying to bind a user Input to an object instanciated via a ResourceDictionary.
<ContentPage.Resources>
<ResourceDictionary>
<model:BusinessObjectsGraphDatasource x:Key="Testdata"
Query="query {
test {
id
description
foo
}
}"
Parameter="{Binding Source={x:Reference QueryParameterEntry}, Path=Text}"/>
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout HorizontalOptions="Center" VerticalOptions="Center" Orientation="Vertical">
<Entry x:Name="QueryParameterEntry"/>
<ListView ItemsSource="{Binding Source={x:StaticResource Testdata}, Path=Result}"/>
</StackLayout>
As you can see, i define an custom Datasource (BusinessObjectsGraphDatasource)object within the ContentPage resources. But this Datasource should be able to handle a parameter given by a Databinding from an Entry.
BusinessObjectGraphDatasource is a class that derives from BindableObject and publishs some BindableProperties (e.g. Parameter)
Can someone give me a hint, how to handle this scenario?
Special scenario notes within this app: i don't have access to a viewmodel or to a code-behind file. the only things i can do is writing controls and resources and use them within xaml.
The Problem here, is that i retrieve a "Sequence contains no matching Elements" exception as soon as i add the Binding to the datasource.
The stacktrace Looks like that:
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.TryAddToProperty(Object element, String localName, Object value, IXmlLineInfo lineInfo, XamlServiceProvider serviceProvider, Exception& exception)
at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.SetPropertyValue(Object xamlelement, XmlName propertyName, Object value, Object rootElement, INode node, HydratationContext context, IXmlLineInfo lineInfo)
at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.Visit(ElementNode node, INode parentNode)
at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Xamarin.Forms.Xaml.FillResourceDictionariesVisitor.Visit(ElementNode node, INode parentNode)
at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Xamarin.Forms.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Xamarin.Forms.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
at Xamarin.Forms.Xaml.XamlLoader.Visit(RootNode rootnode, HydratationContext visitorContext)
at Xamarin.Forms.Xaml.XamlLoader.Load(Object view, String xaml)
at Xamarin.Forms.Xaml.XamlLoader.Load(Object view, Type callingType)
at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml](TXaml view, Type callingType)
at App1.MainPage.InitializeComponent()
at App1.MainPage..ctor()
at App1.App..ctor()
at App1.UWP.MainPage..ctor()
at App1.UWP.App1_UWP_XamlTypeInfo.XamlTypeInfoProvider.Activate_4_MainPage()
at App1.UWP.App1_UWP_XamlTypeInfo.XamlUserType.ActivateInstance()
The Bindable Property is defined like that:
public BindableProperty ParameterProperty = BindableProperty.Create("Parameter", typeof(string),
typeof(BusinessObjectsGraphDatasource), string.Empty, BindingMode.TwoWay, null, ParameterPropertyChanged);
public string Parameter
{
get => (string)GetValue(ParameterProperty);
set => SetValue(ParameterProperty, value);
}
private static void ParameterPropertyChanged(BindableObject bindable, object oldvalue, object newvalue)
{
}
cheers,
chris