个人资料

跳过导航链接首页 > 博客列表 > 博客正文

AutoSuggestBox控件自动填充.

分类:

xmal

                       <AutoSuggestBox.ItemTemplate>
                                <DataTemplate x:DataType="local:ImageBrushAndFileInfo">
                                    <StackPanel Orientation="Horizontal" >
                                        <TextBlock  Text="{x:Bind file.DisplayName}" />
                                        <ToolTipService.ToolTip>
                                            <ToolTip>
                                                <Grid ToolTipService.ToolTip="{x:Bind file.Path}">
                                                    <controls:ImageEx Width="100" gif:AnimationBehavior.RepeatBehavior="Forever"  Source="{x:Bind bitmapImage}">

                                                        <ToolTipService.ToolTip>
                                                            <ToolTip>
                                                                <StackPanel>
                                                                    <TextBlock FontSize="16" Text="{x:Bind file.Name,Mode=OneWay}"></TextBlock>
                                                                    <TextBlock Text="{x:Bind file.DateCreated.UtcDateTime,Mode=OneWay}"></TextBlock>
                                                                </StackPanel>
                                                            </ToolTip>
                                                        </ToolTipService.ToolTip>

                                                    </controls:ImageEx>

                                                </Grid>
                                            </ToolTip>
                                        </ToolTipService.ToolTip>
                                    </StackPanel>
                                </DataTemplate>
                            </AutoSuggestBox.ItemTemplate>

code behind

		private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
		{
			var sList = new List<ImageBrushAndFileInfo>();
			foreach (var group in ImageGroups)
			{

				foreach (var ImgInfo in group.ImageObjects)
				{
					if (ImgInfo.file.Name.Contains(sender.Text))
					{


						sList.Add(ImgInfo);
						Debug.WriteLine(ImgInfo.file.Name);

					}
				}
			}
			sender.ItemsSource = sList;

		}
效果


处理提交

		private void Search_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
		{

			var imgInfo = args.ChosenSuggestion as ImageBrushAndFileInfo;

			sender.Text = imgInfo.file.DisplayName;

			Frame.Navigate(typeof(ImagePage),imgInfo);

		}

songshizhao
最初发表2019/10/19 22:29:50 最近更新2019/10/22 16:01:36 46
为此篇作品打分
10
   评论