【发布时间】:2015-02-04 22:30:41
【问题描述】:
自动建议框中的结果模板未显示,我不知道为什么。我在应用程序中使用 MVVM Light。让我们来看看代码:)
在页面中:
<AutoSuggestBox x:Name="txtBusqueda" x:Uid="txtBusqueda"
ItemsSource="{Binding Lugares}"
Grid.Row="1" Margin="24 24 24 12"
MaxSuggestionListHeight="4" AutoMaximizeSuggestionArea="True"
TextMemberPath="Nombre"
>
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="TextChanged">
<core:InvokeCommandAction Command="{Binding ChangeTextCommand}" CommandParameter="{Binding Text, ElementName=txtBusqueda}" />
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
<AutoSuggestBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Nombre}" TextWrapping="Wrap" />
</DataTemplate>
</AutoSuggestBox.ItemTemplate>
</AutoSuggestBox>
在虚拟机中:
private List<LugarInfo> lugares;
public List<LugarInfo> Lugares
{
get { return this.lugares; }
set
{
if (this.lugares == value) return;
this.lugares = value;
RaisePropertyChanged(() => Lugares);
}
}
public RelayCommand<string> ChangeTextCommand { get; set; }
this.ChangeTextCommand = new RelayCommand<string>(async (s) =>
{
var result = await Api.GetInfoLugares(texto);
List<LugarInfo> lugares = new List<LugarInfo>();
foreach (var lugar in result)
{
lugares.Add(new LugarInfo()
{
Id = int.Parse(lugar.Id),
Tipo = lugar.Tipo,
Nombre = lugar.Nombre
});
}
this.Lugares = lugares;
});
所以,如您所见,没有太多麻烦。 结果被返回并分配给属性:
问题是结果没有显示在控件中,如您在图像中看到的那样。 我们将不胜感激。
【问题讨论】:
-
你添加了那个红色轮廓吗?这通常表明存在绑定问题。
-
@Paul Abbott 当我在虚拟机中设置属性时出现底部红线...
标签: windows-phone-8.1 mvvm-light autosuggest