Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Find an empty element in a Silverlight Grid

Find an empty element in a Silverlight Grid

Scheduled Pinned Locked Moved WPF
csharpjavascriptcsswpfcom
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Neo10101
    wrote on last edited by
    #1

    Well, I have been trying to figure this one out for three days straight and I still haven't come up with a fix. Basically I am trying to swap out the clicked Ellipse with the only empty spot on the 3x3 checkerboard. 8 of the 9 squares are occupied. I need to find the one spot that is not occupied and I can't seem to do it. Why? Because even though there is an empty spot on the grid at runtime, Javascript refuses to acknowledge this. I used the line: var childrenCount = canvasArray[i].children.count; .. so that's all the canvases. If at runtime there is an empty spot, then how come my code refuses to see it? Or am I not writing the right code? How is the empty spot represented and found at runtime? That's what I want to know. Here is the pseudocode: if (squareOnGrid is empty) { log.write(squareOnGrid + ' is empty'); emptySquare = squareOnGrid; oldPositionBorder = sender; oldPositionR = checkerPiece.row; oldPositionC = checkerPiece.col; checkerPiece.row = empty.row; checkerPiece.column = squareOnGrid.column; oldPositionBorder = null; } I want to do this with Javascript (not C#). I already have this (Javascript): function switchPlaces(sender) { for (var i = 0; i < canvasArray.length; i++) { var oldLocationBorderParent = sender; var oldLocationCanvasParent = oldLocationBorderParent.findName('canvas' + (i + 1)); var oldLocationChild = oldLocationCanvasParent.findName('ellipse' + (i + 1)); var childrenCount = canvasArray[i].children.count; log.info(childrenCount); //all of this outputs '1'. It should have a '0' in there, but no. if (childrenCount == 0) { log.info(canvasArray[i] + ' has no children'); var emptySpot = canvasArray[i]; sender['Grid.Row'] = emptySpot['Grid.Row']; sender['Grid.Column'] = emptySpot['Grid.Column']; oldLocationCanvasParent.children.remove(oldLocationChild); } } } Here is my Silverlight code: <Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Loaded="onLoaded" ShowGridLines="True" Background="CornflowerBlue"> <Grid.ColumnDefinitions> <ColumnDefinition Width="100"/> <ColumnDefinition Width="100"/> <ColumnDefinition Width="100"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid.Ro

    M 1 Reply Last reply
    0
    • N Neo10101

      Well, I have been trying to figure this one out for three days straight and I still haven't come up with a fix. Basically I am trying to swap out the clicked Ellipse with the only empty spot on the 3x3 checkerboard. 8 of the 9 squares are occupied. I need to find the one spot that is not occupied and I can't seem to do it. Why? Because even though there is an empty spot on the grid at runtime, Javascript refuses to acknowledge this. I used the line: var childrenCount = canvasArray[i].children.count; .. so that's all the canvases. If at runtime there is an empty spot, then how come my code refuses to see it? Or am I not writing the right code? How is the empty spot represented and found at runtime? That's what I want to know. Here is the pseudocode: if (squareOnGrid is empty) { log.write(squareOnGrid + ' is empty'); emptySquare = squareOnGrid; oldPositionBorder = sender; oldPositionR = checkerPiece.row; oldPositionC = checkerPiece.col; checkerPiece.row = empty.row; checkerPiece.column = squareOnGrid.column; oldPositionBorder = null; } I want to do this with Javascript (not C#). I already have this (Javascript): function switchPlaces(sender) { for (var i = 0; i < canvasArray.length; i++) { var oldLocationBorderParent = sender; var oldLocationCanvasParent = oldLocationBorderParent.findName('canvas' + (i + 1)); var oldLocationChild = oldLocationCanvasParent.findName('ellipse' + (i + 1)); var childrenCount = canvasArray[i].children.count; log.info(childrenCount); //all of this outputs '1'. It should have a '0' in there, but no. if (childrenCount == 0) { log.info(canvasArray[i] + ' has no children'); var emptySpot = canvasArray[i]; sender['Grid.Row'] = emptySpot['Grid.Row']; sender['Grid.Column'] = emptySpot['Grid.Column']; oldLocationCanvasParent.children.remove(oldLocationChild); } } } Here is my Silverlight code: <Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Loaded="onLoaded" ShowGridLines="True" Background="CornflowerBlue"> <Grid.ColumnDefinitions> <ColumnDefinition Width="100"/> <ColumnDefinition Width="100"/> <ColumnDefinition Width="100"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid.Ro

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      I must be missing something here... What is this canvas array and how does it relate to the Silverlight Grid? How does the managed Silverlight code know about the canvas array? How are you calling javascript from managed code?

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups