title: Binding a Dictionary's key and value in a listbox with wpf
body: <p>I am trying to bind a dictionary's key to a row of the grid in a listbox, and bind the dictionary's value to another row of the grid. key's type is Book, a class thati wrote and the value's type is int.
  i want to write  the elements of the class and the integer value in grid.
  Can you help me on this? I'm quite confused on determining the itemsSource and the data type to bind.
  thanks for helping</p>
  
  <p>Edit: i forgot to say that i am using c# - wpf. =)</p>
  
  <hr>
  
  <p>I sent the dictionary as the itemsSource, and i specified the dictionary as type in objectdataprovider tag, and tried to send the value (int) by this code:</p>
  
  <pre><code>&lt; TextBlock Text="{Binding Value, Mode=OneWay}" Grid.Row="1" Width="65" &gt;
  </code></pre>
  
  <p>and the selecteditem was shown as [myNameSpace.Book, 4] instead of only 4.</p>
  
  <hr>
  
  <pre><code>BookListBox.ItemsSource = LibManager.Books;
  </code></pre>
  
  <p>this is what I wrote in Window.xaml.cs and Books is a BookList, where BookList is a type of dictionary&lt; Book, int> .</p>
  
  <p>and the xaml file: </p>
  
  <pre><code>&lt; ListBox Height="571" HorizontalAlignment="Left" Margin="444,88,0,0"
            Name="BookListBox" VerticalAlignment="Top" Width="383" &gt;
          &lt; ListBox.Resources&gt;
              &lt;ObjectDataProvider x:Key="BookData"
                                  ObjectType="{x:Type local:BookList}"/&gt;
          &lt;/ListBox.Resources&gt;
          &lt; ListBox.ItemTemplate&gt;
              &lt; DataTemplate&gt;
                  &lt; Border BorderThickness="2" BorderBrush="Black" Margin="5"
                           CornerRadius="5" Width="350" &gt;
                      &lt; Grid DataContext="{StaticResource BookData}" &gt;
                          &lt; Grid.ColumnDefinitions&gt;
                              &lt; ColumnDefinition/&gt;                        
                          &lt;/Grid.ColumnDefinitions&gt;
                          &lt; Grid.RowDefinitions&gt;
                              &lt; RowDefinition/&gt;
                              &lt; RowDefinition/&gt;
                          &lt; /Grid.RowDefinitions&gt;
                          &lt; Label Content="count: " /&gt;
                          &lt; TextBlock Text="{Binding Value, Mode=OneWay}"
                                      Grid.Row="1" Width="65"/&gt;
                      &lt; /Grid&gt;
                  &lt; /Border&gt;
              &lt; /DataTemplate&gt;
          &lt; /ListBox.ItemTemplate&gt;
      &lt; /ListBox&gt;
  </code></pre>
  
  <hr>
  
  <p>there is one more problem with my code-- I cant see the listed items in listbox. I mean I could get the values by <code>ListBox.SelectedItem</code> but couldn't see in the listbox. thus I can't be sure if I could pass the integer value to where I want.</p>
  
  <p>So I think I also need help for this problem first...
  I write a label that I write by hand, and another label that should be filled by data binding in the same row but I can just see the first label, but I can reach the value in code behind.</p>