我的组合框与谷歌搜索结果绑定。
<ComboBox
Style="{StaticResource ComboBoxStyle}"
IsEditable="True"
IsTextSearchEnabled="False"
ItemsSource="{Binding GoogleSuggest.SuggestedQueries}"
SelectedItem="{Binding GoogleSuggest.SelectedQuery}"
>
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source={Binding IconPath, Converter={StaticResource IconPathToImageSource} Width="32" Height="32" />
<StackPanel Grid.Column="1">
<TextBlock Text="{Binding Query}" Margin="0,8" FontSize="24" />
<TextBlock Text="{Binding URL}" Margin="0,8" FontSize="16" />
</StackPanel>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
我的模型看起来像这样
public class Model_SuggestedQueries : ViewModelBase
{
private string _Query = string.Empty;
public string Query
{
get { return _Query; }
set
{
if (_Query != value)
{
_Query = value;
base.RaisePropertyChanged("Query");
}
}
}
private int _Index = 0;
public int Index
{
get { return _Index; }
set
{
if (_Index != value)
{
_Index = value;
base.RaisePropertyChanged("Index");
}
}
}
private string _URL = 0;
public string URL
{
get { return _URL; }
set
{
if (_URL != value)
{
_URL = value;
base.RaisePropertyChanged("URL");
}
}
}
private string _Icon = 0;
public string Icon
{
get { return _Icon; }
set
{
if (_Icon != value)
{
_Icon = value;
base.RaisePropertyChanged("Icon");
}
}
}
}
但是当我进行选择时,.Text 字段看起来像这样。
如何显示“查询”值而不是对象名称?