Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
XamCarouselPanel binding
posted

I want to bind XamCarouselPanel  to a datatable in access 2003 that contain a image field

i convert the image byte to bitmap

but when i try to bind XamCarouselPanel  with the table don't show anything

The code

 


<ObjectDataProvider x:Key="DBRapido" ObjectType="{x:Type data:cAccesoRapido}" MethodName="GETTABLA" />


<igWindows:XamCarouselPanel  Name="xamCarouselQuickAccess" VerticalAlignment="Bottom" Height="255" Width="737" DataContext="{Binding Source={StaticResource DBRapido}}">
  <igWindows:XamCarouselPanel.ViewSettings>
     <igWindows:CarouselViewSettings IsListContinuous="True" ItemSize="150,150" ItemsPerPage="7">
        <igWindows:CarouselViewSettings.ItemPathRenderPen>
            <Pen Brush="#FFD4CDCD"/>
        </igWindows:CarouselViewSettings.ItemPathRenderPen>
     </igWindows:CarouselViewSettings>
   </igWindows:XamCarouselPanel.ViewSettings>
   <Image Width="100" Height="100" Source="{Binding I_IMAGEN}"/>
</igWindows:XamCarouselPanel>

 

the table contain a field called I_IMAGEN that have the image

in the code behind i transform the image format and return a table with a filed image

DataTable _PASO1= new DataTable();
DataTable _PASO2= new DataTable();

_PASO2.Columns.Add("ID", typeof(String));
_PASO2.Columns.Add("X_DESC", typeof(String));
_PASO2.Columns.Add("I_IMAGEN", typeof(Image));
 if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
    {
      string StrSQL;

      StrSQL = "SELECT * FROM TACCESORAPIDO";

      if (Conexion.Conexion.Consultar(StrSQL, ref _PASO1))
      {
        foreach (DataRow _Fila in _PASO1.Rows)
        {
          Image IMAGEN = ConvertByteArrayToImage((byte[])_Fila[2]);
          _PASO2.Rows.Add(_Fila[0], _Fila[1], IMAGEN);
        }
        _TABLA = _PASO2;
       }
     }

and the convertion

         public static Image ConvertByteArrayToImage(byte[] byteArray)
        {
            if (byteArray != null)
            {
                MemoryStream ms = new MemoryStream(byteArray,0,byteArray.Length);
                ms.Write(byteArray, 0, byteArray.Length);

                try
                {
                    return Image.FromStream(ms,true);
                }
                catch(Exception Error)
                {
                    string _Error = Error.ToString();
                }
               
            }
            return null;
        }

 

 why doesn't work, any help will be great

Antonio From Chile

 

  • 8576
    Offline posted

    Hi Antonio -

    The XamCarouselPanel is just a Panel - like any other panel it does not have support for binding to a list.  If you are using any Panel standalone (i.e., not as the ItemsPresenter of an ItemsControl defived element) you must manually add the elements to display either in XAML (by adding element tags inside the start & end tags of the Panel) or in code behind (by adding elements to the Panel's elements collection via its Children property).

    Have you tried using a XamCarouselListBox instead of a XamCarouselPanel?  (i.e., binding your list to the ItemsSource property of a XamCarouselListBox which internally uses a XamCarouselPanel as its ItemsPresenter).  This should give you the results you are looking for.

    Joe