我创建了一个XamGrid,其中我有一个三级层次结构。我在silverlight 4中创建了它。我在xamgrid上面有一个搜索文本框,它是一个autocompleteBox。当我从AutocompleteBox和priess enter中选择一个项目时,我希望Grid中的该项目得到扩展。我怎样才能做到这一点?? PLZ建议..我的autocomplete bos是:
<local:ExtendedAutoCompleteBox
x:Name="InvNamesSearch"
WaterMark="TypeName"
HorizontalAlignment="Left" VerticalAlignment="Center"
Width="300" Margin="5,0,0,0"
MinimumPrefixLength="3"
IsTextCompletionEnabled="False"
Text="{Binding InvestmentText, Mode=TwoWay}"
ItemsSource="{Binding A,Mode=OneWay}"
SelectedItem="{Binding Path=B, Mode=TwoWay}"
ValueMemberBinding="{Binding A}"
FilterMode="Contains" Canvas.Left="683" Canvas.Top="9"
Command="{Binding AutoSuggestEnterCommand}">
<local:ExtendedAutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="txtAutoSelectedItem" Text="{Binding A}" />
</DataTemplate>
</local:ExtendedAutoCompleteBox.ItemTemplate>
</local:ExtendedAutoCompleteBox>
答案 0 :(得分:1)
XamGrid有一个Rows属性,它是所有根级别行的集合。您可以迭代这些行及其子行,以查找在自动完成框中搜索的数据。找到数据后,可以在相应的行上将IsExpanded属性设置为true。代码可能如下所示:
// This function returns a row that contains the supplied search criteria
public Row FindRowFromAutoCompleteBox(RowCollection rootRows, string searchCriteria)
{
foreach (Row row in rootRows)
{
if (row.Data is LevelOneDataType)
{
if ((row.Data as LevelOneDataType).LevelOneProperty == searchCriteria)
return row;
}
if (row.Data is LevelTwoDataType)
{
if ((row.Data as LevelTwoDataType).LevelTwoProperty == searchCriteria)
return row;
}
if (row.Data is LevelThreeDataType)
{
if ((row.Data as LevelThreeDataType).LevelThreeProperty == searchCriteria)
return row;
}
// Search child rows.
if (row.ChildBands.Count != 0)
{
Row result = FindRowFromAutoCompleteBox(row.ChildBands[0].Rows, searchCriteria);
if (result != null)
return result;
}
}
return null;
}
// Walks up the hierarchy starting at the supplied row and expands parent rows as it goes.
public void ExpandHierarchy(Row row)
{
Row parentRow = null;
// The row is a child of another row.
if (row.ParentRow is ChildBand)
parentRow = (row.ParentRow as ChildBand).ParentRow;
while (parentRow != null)
{
// Expand the row.
parentRow.IsExpanded = true;
if (parentRow.ParentRow is ChildBand)
parentRow = (parentRow.ParentRow as ChildBand).ParentRow;
else
parentRow = null;
}
}
使用这些功能,您现在可以搜索并扩展到您想要的行。
Row result = FindRowFromAutoCompleteBox(xamGrid1.Rows, "Value");
if (result != null)
{
ExpandHierarchy(result);
result.IsSelected = true;
}