Binding AutoCompleteBox inside DataTemplate
I have the following AutoCompleteBox defined inside DataTemplate:
<Window.Resources>
<DataTemplate x:key="PaneTitleTemplate">
<Grid>
<Grid.ColumnDefinitions>
<Co开发者_运维问答lumnDefinition />
<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?
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.
精彩评论