Skip to main content

Microsoft Silverlight

Answered Question Databinding with AccordionRSS Feed

(0)

moinshiraz
moinshiraz

Member

Member

1 points

2 Posts

Databinding with Accordion

 Hi,

I am trying to do databinding with accordion, and I am unable to do it.

I am new to silverlight. Below is my code. I would be glad, if anyone would be able to help me make it work.

Thanks & regards,

 Moin 

------MainPage.xaml--------

 <ScrollViewer VerticalScrollBarVisibility="Visible" x:Name="scrMain2" HorizontalAlignment="Stretch" Grid.Row="0">
            <layoutToolkit:Accordion x:Name="Accordion1" SelectionMode="ZeroOrMore">
                    <layoutToolkit:AccordionItem>
                        <layoutToolkit:AccordionItem.HeaderTemplate>
                            <DataTemplate>
                                <StackPanel HorizontalAlignment="Stretch">
                                    <TextBlock Text="{Binding DateVisited}" FontSize="12" />
                                    <TextBlock Text="{Binding CC}" FontSize="12" />
                                    <TextBlock Text="Doctor :" FontSize="12"/>
                                    <TextBlock Text="{Binding Doctor}" FontSize="12"  />
                                    <TextBlock Text="{Binding Place}" FontSize="12"  />
                                </StackPanel>
                            </DataTemplate>
                        </layoutToolkit:AccordionItem.HeaderTemplate>
                        <layoutToolkit:AccordionItem.ContentTemplate>
                            <DataTemplate>
                                <StackPanel VerticalAlignment="Stretch">
                                    <StackPanel HorizontalAlignment="Stretch">
                                        <TextBlock Text="Doctor :" FontSize="12"/>
                                        <TextBlock Text="{Binding Doctor}" FontSize="12"/>
                                    </StackPanel>
                                    <StackPanel HorizontalAlignment="Stretch">
                                        <TextBlock Text="HPI :" FontSize="12"/>
                                        <TextBlock Text="{Binding HPI}" FontSize="12"/>
                                    </StackPanel>
                                    <StackPanel HorizontalAlignment="Stretch">
                                        <TextBlock Text="ROS :" FontSize="12"/>
                                        <TextBlock Text="{Binding ROS}" FontSize="12"/>
                                    </StackPanel>
                                    <StackPanel HorizontalAlignment="Stretch">
                                        <TextBlock Text="PMH :" FontSize="12"/>
                                        <TextBlock Text="{Binding PMH}" FontSize="12"/>
                                    </StackPanel>
                                    <StackPanel HorizontalAlignment="Stretch">
                                        <TextBlock Text="SH :" FontSize="12"/>
                                        <TextBlock Text="{Binding SH}" FontSize="12"/>
                                    </StackPanel>
                                    <StackPanel HorizontalAlignment="Stretch">
                                        <TextBlock Text="FH :" FontSize="12"/>
                                        <TextBlock Text="{Binding FH}" FontSize="12"/>
                                    </StackPanel>
                                    <StackPanel HorizontalAlignment="Stretch">
                                        <TextBlock Text="Allergies :" FontSize="12"/>
                                        <TextBlock Text="{Binding Allergies}" FontSize="12"/>
                                    </StackPanel>
                                    <StackPanel HorizontalAlignment="Stretch">
                                        <TextBlock Text="Meds :" FontSize="12"/>
                                        <TextBlock Text="{Binding Meds}" FontSize="12"/>
                                    </StackPanel>
                                    <StackPanel HorizontalAlignment="Stretch">
                                        <TextBlock Text="Vitals :" FontSize="12"/>
                                        <TextBlock Text="{Binding Vitals}" FontSize="12"/>
                                    </StackPanel>
                                    <StackPanel HorizontalAlignment="Stretch">
                                        <TextBlock Text="PE :" FontSize="12"/>
                                        <TextBlock Text="{Binding PE}" FontSize="12"/>
                                    </StackPanel>
                                    <StackPanel HorizontalAlignment="Stretch">
                                        <TextBlock Text="A/P :" FontSize="12"/>
                                        <TextBlock Text="{Binding AP}" FontSize="12"/>
                                    </StackPanel>
                                </StackPanel>
                            </DataTemplate>
                        </layoutToolkit:AccordionItem.ContentTemplate>
                    </layoutToolkit:AccordionItem>
            </layoutToolkit:Accordion>
        </ScrollViewer>

 ----------MainPage.xaml.cs-------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace iEMR_Recent_Activities
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            try
            {
                InitializeComponent();
                FillAccordion();
            }
            catch (System.Exception ee)
            {
                throw ee;
            }
        }
        public void FillAccordion()
        {
            Accordion1.ItemsSource = new[] {

                       new metaData("08/04/09", "Hypertension", "Mike Mitchel", "Wood Grove", "AAAAA", "BBBB", "CCCC", "DDDD","EEEE","FFFF","GGGG","HHHH","IIII","JJJJ"),

                       new metaData("08/04/09", "Hypertension", "Mike Mitchel", "Wood Grove", "AAAAA", "BBBB", "CCCC", "DDDD","EEEE","FFFF","GGGG","HHHH","IIII","JJJJ"),

                       new metaData("08/04/09", "Hypertension", "Mike Mitchel", "Wood Grove", "AAAAA", "BBBB", "CCCC", "DDDD","EEEE","FFFF","GGGG","HHHH","IIII","JJJJ")};
           }
    }

    public class metaData
    {
        public metaData(string _dateVisited,string _cc,string _doctor,string _place,string _hpi,string _ros,string _pmh, string _sh, string _fh, string _allergies,string _meds,string _vitals,string _pe, string _ap)
        {
            DateVisited = _dateVisited;
            CC = _cc;
            Doctor = _doctor;
            Place = _place;
            HPI = _hpi;
            ROS = _ros;
            PMH = _pmh;
            SH = _sh;
            FH = _fh;
            Allergies = _allergies;
            Meds = _meds;
            Vitals = _vitals;
            PE = _pe;
            AP = _ap;
        }
        public string DateVisited { get; set; }
        public string CC { get; set; }
        public string Doctor { get; set; }
        public string Place { get; set; }
        public string HPI { get; set; }
        public string ROS { get; set; }
        public string PMH { get; set; }
        public string SH { get; set; }
        public string FH { get; set; }
        public string Allergies { get; set; }
        public string Meds { get; set; }
        public string Vitals { get; set; }
        public string PE { get; set; }
        public string AP { get; set; }
    }
}
 

 

Ruurd Boeke
Ruurd Boeke

Participant

Participant

821 points

110 Posts

Microsoft
Answered Question

Re: Databinding with Accordion

Hi,

The xaml creates an accordionitem and then sets a headertemplate and contenttemplate on that accordionitem.
Could you please change that? You should not create an accordionitem in the xaml, and only define the itemtemplate (which becomes the headertemplate in the AccordionItems) and the contenttemplate on Accoridon....

Your xaml would end up looking something like this:

<accordion>
 <Accordion.ItemTemplate>....</>
  <Accordion.ContentTemplate>..</>

Hope that helps

-- RJ (Ruurd Johan Boeke) [MSFT]
Silverlight
http://www.sitechno.com/blog

moinshiraz
moinshiraz

Member

Member

1 points

2 Posts

Re: Re: Databinding with Accordion

 Thanks a ton. that did solve the problem.

Thanks again,

Moin

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities