Forum General

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Xamarin C# Double Binding Source

Emixam23Emixam23 USMember ✭✭✭

Is it possible to have 2 sources of binding? from an element such as CellView?

I searched and tried several possibilities I had in my mind without be able to do what I want to do. It seems so simple however..

Let says I have this page (I put a simple code, it is just a bit long, but not hard):

MainPage.cs

public partial class Courses: ContentPage
{
    // Course it's the element "data template" for the listView
    private class Course
    {
        public string Date { get; set; }
        public string Destination { get; set; }

        private string _price;
        public string Price {
            get { return this._price; }
            set
            {
                this._price = "€" + value;
            }
        }
    }

    // FontAttribute it's the other element which is not set as ItemsSource, but used from the cell to get the FontFamily ask, the FontSize etc 
    private class FontAttributes
    {
        public string MOON_FAMILY_ALIEN_BOLD { get; set; }
        ....

        public FontAttributes()
        {
            ....
        }
    }
    public FontAttributes FontAttr;

    public CoursesHistory()
    {
        FontAttr = new FontAttributes();
        InitializeComponent();
        InitList();
    }

    private void InitList()
    {
        ObservableCollection<Course> courses = new ObservableCollection<Course>();
        ListViewHistory.ItemsSource = courses;

        courses.Add(new Course() { Date = "1 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "2 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "3 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "4 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "5 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "6 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "7 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "8 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "9 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "10 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "11 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "12 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "13 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "14 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
        courses.Add(new Course() { Date = "15 Novembre 1995", Destination = "Le Mans", Price = "23.11" });
    }
}

and then its XAML MainPage.xaml.cs

<?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="Pages.CoursesHistory">
    <AbsoluteLayout>

      <ListView x:Name="ListViewHistory" BackgroundColor="White" RowHeight="50"
              AbsoluteLayout.LayoutBounds="0.5,0.5,1,1"
              AbsoluteLayout.LayoutFlags="All">
        <ListView.ItemTemplate>
          <DataTemplate>
            <ViewCell>

              <AbsoluteLayout>

The list is Bind with my ObservableCollection so how can I access FontAttr which is not bind?

                <Label FontFamily="{Binding Path=HOW_CAN_I_ACCESS_FONTATTR??}" 
                       Text="{Binding Date}" TextColor="Black" FontSize="14" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"
                       AbsoluteLayout.LayoutBounds="0, 0.5, 0.3, 1"
                       AbsoluteLayout.LayoutFlags="All"/>
                <Label Text="{Binding Destination}" TextColor="Black" FontSize="14" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"
                       AbsoluteLayout.LayoutBounds="0.5, 0.5, 0.5, 1"
                       AbsoluteLayout.LayoutFlags="All"/>
                <Label Text="{Binding Price}" TextColor="Black" FontSize="14" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"
                       AbsoluteLayout.LayoutBounds="1, 0.5, 0.2, 1"
                       AbsoluteLayout.LayoutFlags="All"/>
              </AbsoluteLayout>

            </ViewCell>
          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>

    </AbsoluteLayout>
  </ContentPage>

Thank for read and for your help !

Tagged:

Best Answers

Answers

  • Emixam23Emixam23 USMember ✭✭✭
    edited June 2016

    Interesting :open_mouth: I'll take a look :) Thank !

  • Emixam23Emixam23 USMember ✭✭✭
    edited June 2016

    I didnt reply but with the first answer, I had an idea and then, I tought about IMarkup. I so merged the code given by @JRolandros and IMarkup and everything works better than what I wanted to do, thank !

  • Jenitha.2420Jenitha.2420 USMember ✭✭
    edited March 2020

    How can I set the class as Source. can anyone help me ASAP?




    Here Loader is the class file. Its not a converter file. How can I use the "lcal" for Isvisible Property?

Sign In or Register to comment.