views:

19

answers:

1

i have a listbox who takes values from Dictionary Size:

this is the Size type:

public Dictionary<string, int> Size
    {
        get;
        private set;
    }

this is my listbox

<ListBox x:Name="boardSize" ItemsSource="{Binding Size}" ItemTemplate="{DynamicResource DataTemplate1}" />

this is my the associated DataTemplate:

<Rectangle Margin="8,8,16,8" Stroke="Black" RadiusX="45" RadiusY="45">
 <Rectangle.Fill>
  <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
   <GradientStop Color="Black" Offset="0"/>
   <GradientStop Color="#FFE24A4A" Offset="1"/>
  </LinearGradientBrush>
 </Rectangle.Fill>
</Rectangle>
<TextBlock x:Name="textBlock" **Text="{Binding path=Size}"**/>

I have two problems:

  1. where I putted ** I want the textblock text to contain the Size key value
  2. how can I do command pattern when a button is pushed ?
+2  A: 

Inside the ItemTemplate, the DataContext is an item from the source collection, so in that case it's a KeyValuePair<string, int>. So the path to the key is just "Key" :

<TextBlock x:Name="textBlock" Text="{Binding path=Key}"/>

Your second question is not very clear, what do you want to do exactly ? Usually, binding to commands is used in MVVM: you bind to a ICommand property exposed by your ViewModel. However in your case there is not ViewModel, since your data object is a KeyValuePair<string, int>... Please give more details if you want a more complete answer

Thomas Levesque
mate where were you an hour ago :) i found the same answer in http://windowsclient.net/learn/video.aspx?v=30804 thank you ...about the command i want this to invoke another grid (i want to make a bord game and this is my board size...) you can find more info here :http://stackoverflow.com/questions/3846668/how-to-dynamicly-set-board-for-board-gamesize-using-xmal-in-wpf
yoav.str