Hi,
I modified your class as suggested and don't have that error. Please provide test page which uses your ImageViewer
Here is my test case
<%@ Page Language="C#" %>
<%@ Import Namespace="Coolite.Ext.Web" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.IO" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
public class VwImage
{
public Coolite.Ext.Web.Image Image { get; set; }
public string Url { get; set; }
public string Name { get; set; }
public string OriginalUrl { get; set; }
}
public class ImageViewer : Window
{
#region variables
private Coolite.Ext.Web.Panel _leftPanel = new Coolite.Ext.Web.Panel();
private Coolite.Ext.Web.Panel _southPanel = new Coolite.Ext.Web.Panel();
private Coolite.Ext.Web.Panel _mainPanel = new Coolite.Ext.Web.Panel();
private Coolite.Ext.Web.Panel _rightPanel = new Coolite.Ext.Web.Panel();
private List<string> _imagesNames = new List<string>();
#endregion
#region Properties
private Coolite.Ext.Web.Image _mainImage;
public Coolite.Ext.Web.Image MainImage
{
get
{
EnsureChildControls();
return _mainImage;
}
set
{
EnsureChildControls();
_mainImage = value;
}
}
private List<Coolite.Ext.Web.Image> _imagesContainer;
public List<Coolite.Ext.Web.Image> ImagesContainer
{
get
{
EnsureChildControls();
return _imagesContainer;
}
set
{
EnsureChildControls();
_imagesContainer = value;
}
}
private List<VwImage> _imagesThumbnailContainer;
public List<VwImage> ImagesThumbnailContainer
{
get { return _imagesThumbnailContainer; }
set { _imagesThumbnailContainer = value; }
}
private int _containerSize;
public int ContainerSize
{
get
{
EnsureChildControls();
return _containerSize;
}
set
{
EnsureChildControls();
_containerSize = value;
}
}
private string _path;
public string Path
{
get
{
EnsureChildControls();
return _path;
}
set
{
EnsureChildControls();
_path = value;
}
}
#endregion
#region Constructors
public ImageViewer(string path, List<string> imagesNames)
{
try
{
if (Directory.Exists(path))
{
_path = path;
_containerSize = Directory.GetFiles(path).GetUpperBound(0) + 1;
_imagesContainer = new List<Coolite.Ext.Web.Image>();
_imagesNames = imagesNames;
foreach (var imagesInfo in Directory.GetFiles(path))
{
foreach (var imagesName in imagesNames)
{
if (imagesInfo.Contains(imagesName))
{
Coolite.Ext.Web.Image image = new Coolite.Ext.Web.Image();
image.ImageUrl = imagesInfo;
_imagesContainer.Add(image);
}
}
}
_mainImage = _imagesContainer[0];
_mainPanel.BodyControls.Add(_mainImage);
List<VwImage> cimages = new List<VwImage>();
foreach (var image in _imagesContainer)
{
var cimage = new VwImage();
cimage.Image = image;
cimage.Url = image.ImageUrl;
cimages.Add(cimage);
}
DataView dataview = new DataView();
Store store = new Store();
store.DataSource = cimages;
store.DataBind();
//XTemplate xTemplate = new XTemplate();
//xTemplate.CustomConfig.Add(new ConfigItem("html", "['<ul class=\"\">','<tpl for=\".\">','<li><div class=\"\"><img src=\"{Url}\"></div><span>{Name}</span></li>','</tpl>','</ul>','']", ParameterMode.Raw));
dataview.Template.Text = "<ul class=\"\"><tpl for=\".\"><li><div class=\"\"><img src=\"{Url}\"></div><span>{Name}</span></li></tpl></ul>";
dataview.StoreID = store.ID;
dataview.ItemSelector = "div";
dataview.StyleSpec = "overflow:auto";
dataview.MultiSelect = true;
_leftPanel.Items.Add(dataview);
}
}
catch (Exception ex)
{
Ext.MessageBox.Alert("ImageViewer", ex.Message);
}
}
#endregion
#region Override
public override void Show()
{
InitializeWindow();
base.Show();
}
#endregion
#region Private Methods
private void InitializeWindow()
{
//Panels
_southPanel.ID = "SouthPanel" + Guid.NewGuid().ToString().Substring(0, 5);
_southPanel.Height = Unit.Pixel(25);
_southPanel.BodyStyle = "padding:6px;";
_rightPanel.ID = "RightPanel" + Guid.NewGuid().ToString().Substring(0, 5);
_rightPanel.Width = Unit.Pixel(95);
_rightPanel.BodyStyle = "padding:6px;";
_leftPanel.ID = "LeftPanel" + Guid.NewGuid().ToString().Substring(0, 5);
_leftPanel.Width = Unit.Pixel(100);
_leftPanel.BodyStyle = "padding:6px;";
_mainPanel.ID = "MainPanel" + Guid.NewGuid().ToString().Substring(0, 5);
_mainPanel.BodyStyle = "padding:6px;";
//Buttons
var btnPrint = new Coolite.Ext.Web.Button();
btnPrint.ID = "btnPrint" + Guid.NewGuid().ToString().Substring(0, 5);
btnPrint.Text = "Print";
btnPrint.MinWidth = Unit.Pixel(80);
btnPrint.Icon = Coolite.Ext.Web.Icon.Printer;
var btnSave = new Coolite.Ext.Web.Button();
btnSave.ID = "btnSave" + Guid.NewGuid().ToString().Substring(0, 5);
btnSave.Text = " Save";
btnSave.MinWidth = Unit.Pixel(80);
btnSave.Icon = Coolite.Ext.Web.Icon.Disk;
var btnZoomIn = new Coolite.Ext.Web.Button();
btnZoomIn.ID = "btnZoomIn" + Guid.NewGuid().ToString().Substring(0, 5);
btnZoomIn.Text = " ZoomIn";
btnZoomIn.MinWidth = Unit.Pixel(80);
btnZoomIn.Icon = Coolite.Ext.Web.Icon.MagnifierZoomIn;
var btnZooOut = new Coolite.Ext.Web.Button();
btnZooOut.ID = "btnZooOut" + Guid.NewGuid().ToString().Substring(0, 5);
btnZooOut.Text = " ZoomOut";
btnZooOut.MinWidth = Unit.Pixel(80);
btnZooOut.Icon = Coolite.Ext.Web.Icon.ZoomOut;
_rightPanel.BodyControls.Add(btnPrint);
_rightPanel.BodyControls.Add(btnSave);
_rightPanel.BodyControls.Add(btnZoomIn);
_rightPanel.BodyControls.Add(btnZooOut);
//Layout
var layout = new BorderLayout();
// Set West Region properties
layout.West.Split = true;
layout.West.Collapsible = true;
// Set East Region properties
layout.East.Split = false;
layout.East.Collapsible = true;
// Set South Region properties
layout.South.Split = false;
layout.South.Collapsible = false;
// Add Panels to BorderLayout Regions
layout.West.Items.Add(_leftPanel);
layout.Center.Items.Add(_mainPanel);
layout.East.Items.Add(_rightPanel);
layout.South.Items.Add(_southPanel);
// Make Window to hold everything
ID = "Window" + Guid.NewGuid().ToString().Substring(0, 5);
Title = "ImageViewer";
Icon = Coolite.Ext.Web.Icon.Application;
Plain = true;
Border = false;
BodyBorder = false;
Collapsible = false;
// Add BorderLayout to Window
Items.Add(layout);
// Add Window to Form
((Page)HttpContext.Current.Handler).Page.Controls.Add(this);
}
private static System.Drawing.Image ConvertByteArrayToImage(byte[] byteArray)
{
if (byteArray != null)
{
MemoryStream ms = new MemoryStream(byteArray, 0,
byteArray.Length);
ms.Write(byteArray, 0, byteArray.Length);
System.Drawing.Image myImg = System.Drawing.Image.FromStream(ms);
ms.Close();
return myImg;
}
return null;
}
private static System.Drawing.Image ResizeImage(System.Drawing.Image imgToResize, System.Drawing.Size size)
{
try
{
int sourceWidth = imgToResize.Width;
int sourceHeight = imgToResize.Height;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)size.Width / (float)sourceWidth);
nPercentH = ((float)size.Height / (float)sourceHeight);
nPercent = nPercentH < nPercentW ? nPercentH : nPercentW;
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
System.Drawing.Bitmap b = new System.Drawing.Bitmap(destWidth, destHeight);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
g.Dispose();
return b;
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}
#endregion
}
protected void Page_Load(object sender, EventArgs e)
{
this.Form.Controls.Add(new ImageViewer("", new List<string>()));
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManagerProxy" runat="server" />
</form>
</body>
</html>