HI,
I am testing touch capabilities of my chipworx module (v1.2 , last firmwares).
I have created a SimpleTouchScreenImage class derived from Image.
public class SimpleTouchScreenImage:Image
{
public string NameId { get; set; }
public SimpleTouchScreenImage(Bitmap oneBitmap, string targetName)
{
this.Bitmap= oneBitmap;
NameId = targetName;
}
}
Next I add 2 instances to my canvas with Touch Down event :
// SECTION CODE 1
// debug OK : if touch then event is fire
SimpleTouchScreenImage btImg = new SimpleTouchScreenImage(
Resources.GetBitmap(Resources.BitmapResources.flecheBleuGauche),
"flecheBleuGauche");
btImg.TouchDown += new TouchEventHandler(menu1_TouchDown);
Canvas.SetLeft(btImg, 250);
Canvas.SetTop(btImg, 100);
mainCanvas.Children.Add(btImg);
SimpleTouchScreenImage btImg2 = new SimpleTouchScreenImage(
Resources.GetBitmap(Resources.BitmapResources.flecheBleuDroite),
"flecheBleuDroite");
btImg2.TouchDown += new TouchEventHandler(menu1_TouchDown);
Canvas.SetLeft(btImg2, 300);
Canvas.SetTop(btImg2, 100);
mainCanvas.Children.Add(btImg2);
And my touch handler (not finish- just for debug purpose) is :
void menu1_TouchDown(object sender, TouchEventArgs e)
{
int x;
int y;
// StackPanel st = sender as StackPanel; //who send touch down event message
SimpleTouchScreenImage touchImg = (e.OriginalSource) as SimpleTouchScreenImage;
if (touchImg != null)
{
switch (touchImg.NameId)
{
case "flecheBleuBas": _text.TextContent = "DOWN ----captured at (";
break;
case "flecheBleuHaut": _text.TextContent = "UP ----captured at (";
break;
case "flecheBleuGauche": _text.TextContent = "LEFT ----captured at (";
break;
case "flecheBleuDroite": _text.TextContent = "RIGHT ----captured at (";
break;
}
e.GetPosition((UIElement)sender, 0, out x, out y); // retrieve coord
_text.TextContent +=x.ToString() + "," + y.ToString() + ")"; // add coord
}
_text.ForeColor = ColorUtility.ColorFromRGB(255, 0, 0);
}
Emulator and test on chipworx are OK…
Now i would like to do the same with Stackpanel container:
// SECTION CODE 2
//KO NO TOUCH fire event!!!
//new container stackpanel type SimpleTouchScreenImage
StackPanel menu1 = new StackPanel();
ArrayList imgMenuArray = new ArrayList();
imgMenuArray.Add(new SimpleTouchScreenImage (
Resources.GetBitmap(Resources.BitmapResources.flecheBleuBas),
"flecheBleuBas" )
);
imgMenuArray.Add(new SimpleTouchScreenImage(
Resources.GetBitmap(Resources.BitmapResources.flecheBleuHaut),
"flecheBleuHaut")
);
foreach (SimpleTouchScreenImage img in imgMenuArray)
menu1.Children.Add(img); // add all in stackpanel
menu1.Orientation = Orientation.Vertical;
menu1.TouchDown+=new TouchEventHandler(menu1_TouchDown);
Canvas.SetLeft(menu1, 25);
Canvas.SetTop(menu1, 25);
mainCanvas.Children.Add(menu1); // attach StackPanel to canvas with specified position
Emulator test is OK but test on ChipWorks fails: touch event is never fired.
Is there something wrong with the code?
Thanks for your help.
(I don’t find file atachment to joint my source file)
Chris