tags:

views:

29

answers:

1

I have the following AutoCompleteBox defined inside DataTemplate:

<Window.Resources>
  <DataTemplate x:key="PaneTitleTemplate">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
      </Grid.ColumnDefinition>
      <ContentPresenter Content="{Binding}" />
      <toolkit:AutoCompleteBox x:Name="InsertBox" ItemsSource="{???}" />
    </Grid>
  </DataTemplate>
</Window.Resources>
...
<radRock:RadPane x:Name="pane1" TitleTemplate="{StaticResource PaneTitleTemplate}"/>

Now I'd like to fill it with a list of strings, but I don't know which Binding should I use. The list of strings is an instance variable from the Window. What should I do?

+1  A: 

Part of the question is what is your DataContext. If it is the Window itself or is it some other object. If it is the Window then you don't need to specify it in the binding, if it some other object then you must specify that you are using the Window as the binding source. I think the binging you want is as follows (you can remove the ElementName if the Window is the DataContext):

ItemsSource="{Binding StringListName, ElementName=WindowName}"

Obviously replace StringListName and WindowName with the name they actually have in your window.

Craig Suchanec
I'm not familiar with the concept of DataContext, but I've tried {Binding StringListName, ElementName=MainWindow}, and it still didn't work. StringListName is a public member of MainWindow.xaml.cs. If I handle the Loaded event and assign ItemsSource manually, it works.
Thiago
Never mind, got it right by debugging and you're right.
Thiago