[BINDING] Problème de binding sur un AutoCompleteBox
Bonjour,
J'arrive à réaliser un binding sur un AutoCompleteBox avec une liste de string, par contre mon problème est que je n'y arrive pas un business object.
Voici me code serveur permettant de remplir les items de ma AutoCompleteBox ainsi que de filtrer mes items :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
void svc_GetItemsCompleted(object sender, GetCompaniesCompletedEventArgs e)
{
XDocument xDoc = XDocument.Parse(e.Result.ToString());
var objects = from obj in xDoc.Descendants("ITEM")
select new MyItem
{
Key = company.Attribute("ID").Value,
Value = company.Attribute("LABEL").Value
};
this.myautocompletebox.DataContext = objects;
this.myautocompletebox.ItemFilter = (search, item) =>
{
MyItem cboItem = item as MyItem;
if (null != cboItem)
{
return (cboItem.Value.ToLower().Contains(filter.ToLower()));
}
return false;
};
}
public class MyItem
{
public string Key { get; set; }
public string Value { get; set; }
public override string ToString()
{
return Value;
}
} |
Ensuite mon contrôle dans le xaml :
Code:
1 2
|
<input:AutoCompleteBox x:Name="myautocompletebox" FilterMode="Custom" ItemsSource="{Binding}" Style="{StaticResource CustomAutoCompleteBox}"/> |
Et enfin mon style :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
<Style x:Key="CustomAutoCompleteBox" TargetType="input:AutoCompleteBox">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Value}"/>
<TextBlock Text=" - "/>
<TextBlock Text="{Binding Key}"/>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style> |
Le résultat ?
Il n'y pas de binding !!!!
J'avoue ne rien comprendre !
Merci de votre aide.