Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 24th, 2011  |  syntax: None  |  size: 1.31 KB  |  views: 40  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <Window x:Class="ToolBarBindingTest.MainWindow"
  2.                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.                 xmlns:tb="..."
  5.                 Title="MainWindow" Height="350" Width="525">
  6.         <StackPanel>
  7.                 <!-- This works as expected - when I type into the text box, the text appears
  8.                 in the tool bar. -->
  9.                 <TextBox Name="text"/>
  10.                 <ToolBarTray>
  11.                         <ToolBar>
  12.                                 <TextBlock Text="{Binding Text, ElementName=text}"></TextBlock>
  13.                         </ToolBar>
  14.                 </ToolBarTray>
  15.  
  16.                 <!-- This doesn't work. The only difference I can is that the regular ToolBar is
  17.                 ItemsControl and therefore uses ItemsCollection as its collection, where my
  18.                 tb:ToolBar uses FreezableCollection<tb:TooBarControl>. For reasons I'm not really
  19.                 going to detail (because it is irrelevant),     I need strongly typed collection.
  20.                
  21.                 A binding error is produced:
  22.                 System.Windows.Data Error: 4 : Cannot find source for binding with reference
  23.                 'ElementName=text2'. BindingExpression:Path=Text; DataItem=null; target element
  24.                 is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
  25.                  -->
  26.                 <TextBox Name="text2"/>
  27.                 <tb:ToolBar>
  28.                         <tb:ToolBarControl>
  29.                                 <TextBlock Text="{Binding Text, ElementName=text2}"></TextBlock>
  30.                         </tb:ToolBarControl>
  31.                 </tb:ToolBar>
  32.         </StackPanel>
  33. </Window>
  34.  
  35.