0

i'm new to wpf , i need to place a tow different drawing inside an item-controls items according to a specific binding value ,

the item control is for this case a button with a canvas in its content i need to render the drawing onto the canvas after performing a check on the bounded value

the item control is bounded to an ObservableCollection of Employee's

The Data Template is as follows (just the relative properties)

   <Button>
        <Grid>
            <ViewBox>
                  <Canvas>
                        <!-- Here go some shapes that -->
                  </Canvas>
              </ViewBox>         
        </Grid>
   </Button>

my question is , how to go about rendering the shapes through the Binding source i thought about a converter which would manually add the shapes from code behind but i cant figure out which of the canvas's properties to Bind .

any idea's would be appreciated.

Simon Sarris
  • 62,212
  • 13
  • 141
  • 171
eran otzap
  • 12,293
  • 20
  • 84
  • 139

1 Answers1

2

You ca use the Canvas.Children property. You can place each single element by calling Canvas.SetTop(), Canvas.SetLeft() on each shape. I agree that some custom converter can do the job you want.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
  • this is a good approach but i still fail to see how i can bind to the children property http://stackoverflow.com/questions/889825/wpf-is-it-possible-to-bind-a-canvass-children-property-in-xaml – eran otzap Nov 14 '11 at 13:25
  • try with an attached property and bind that property – Felice Pollano Nov 14 '11 at 13:54
  • sorry , i'm new to wpf you mean i need to do something along the lines of this : well the first problem would be that there doesn't seem to be an attached property of children only which i can't Bind any thing to (or don't know how) – eran otzap Nov 14 '11 at 14:05
  • @eran you could not bind the children, but you can create your own attached property and drive the children colection from there. – Felice Pollano Nov 14 '11 at 14:44