Ok, this is driving me crazy.
I'm using a list of this model on my ViewModel
public class NodeModel
{
string Id { get; set; }
string varName { get; set; }
int varQuantity { get; set; }
double price { get; set; }
}
I'm doing a custom control, with a ListView inside. I could add bindable properties to background color, height request, and even set the text color using this:
<·StackLayout
x:Name="stk_FilteredList"
IsEnabled="False"
IsVisible="False">
<·ScrollView>
<·ListView
x:Name="lv_list"
HasUnevenRows="True"
IsPullToRefreshEnabled="False"
IsEnabled="False"
IsVisible="False">
<·ListView.ItemTemplate>
<·DataTemplate>
<·TextCell x:Name="lv_cell"/>
<·/DataTemplate>
<·/ListView.ItemTemplate>
<·/ListView>
<·/ScrollView>
<·/StackLayout>
Code Behind:
public static readonly BindableProperty SB_ListTextColorProperty = BindableProperty.Create(nameof(SB_ListTextColor), typeof(Color), typeof(SearchBarView), Color.Black, BindingMode.OneWay);
public Color SB_ListTextColor
{
get { return (Color)GetValue(SB_ListTextColorProperty); }
set
{
SetValue(SB_ListTextColorProperty, value);
OnPropertyChanged(() => SB_ListTextColorProperty);
}
}
(...)
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == SB_ListTextColorProperty.PropertyName)
lv_list.ItemTemplate.SetValue(TextCell.TextColorProperty, SB_ListTextColor);
}
So, from the main XAML I can do this:
<·customControls:SearchBarView
SB_BackgroundColor="Yellow"
SB_ItemsSource = "{Binding NodeModelList}"
SB_ListTextColor="{x:Static statics:Palette._MainColorDark}"/>
But now I need to tell the new cotrol to use "Id" or "varName" as the value of the Text property of the default DataTemplate, from the main XAML. And it has to be from the main XAML because I want to use this control with other Models, so I can't use custom DataTemplate.
Do you understand what I want to do? ^^U
Thank you!