列表视图中的WPF磁贴搜索
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了列表视图中的WPF磁贴搜索相关的知识,希望对你有一定的参考价值。
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:EPOS.Desktop.UserControls"
xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" xmlns:dxnav="http://schemas.devexpress.com/winfx/2008/xaml/navigation"
x:Class="EPOS.Desktop.UserControls.QeueOrders" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="600"
xmlns:tiles="clr-namespace:EPOS.Desktop.ViewModel">
<UserControl.DataContext>
<tiles:DemoViewModel x:Name="xyz"/>
</UserControl.DataContext>
<UserControl.Resources>
<StackPanel x:Key="tileTemplate">
<ListView>
<ListView.ItemTemplate>
<dxlc:Tile Content="{Binding Name}"/>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</UserControl.Resources>
<Grid>
<dxlc:TileLayoutControl ItemsSource="{Binding demos}" ItemTemplate="{StaticResource tileTemplate}" Grid.RowSpan="2"
Margin="21,0,-21,0"/> <!-- <dxlc:Tile Header="{Binding Name}" Click="Tile_Click" /> -->
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="144,10,0,0" TextWrapping="Wrap" Text="TextBox"
VerticalAlignment="Top" Width="120"/>
</Grid>
</UserControl>
我想在WPF中搜索图块。到目前为止,我发现只有使用listview才有可能。如果您了解其他最佳方式,请分享解决方案。
答案
this is xml:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:EPOS.Desktop.UserControls"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" xmlns:dxnav="http://schemas.devexpress.com/winfx/2008/xaml/navigation" x:Class="EPOS.Desktop.UserControls.QeueOrders"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="600"
xmlns:tiles="clr-namespace:EPOS.Desktop.ViewModel"
>
<UserControl.DataContext>
<tiles:DemoViewModel x:Name="xyz"/>
</UserControl.DataContext>
<Grid>
<!--<dxlc:TileLayoutControl ItemsSource="{Binding demos}" ItemTemplate="{StaticResource tileTemplate}" Grid.RowSpan="2" Margin="21,0,-21,0" />-->
<!-- <dxlc:Tile Header="{Binding Name}" Click="Tile_Click" /> -->
<dxlc:TileLayoutControl Name="tileLayoutControl" ItemsSource="{Binding demos}" >
<dxlc:TileLayoutControl.ItemTemplate>
<DataTemplate>
<dxlc:Tile Header="{Binding Name}" Content="{Binding Name}"/>
</DataTemplate>
</dxlc:TileLayoutControl.ItemTemplate>
</dxlc:TileLayoutControl>
<Grid>
<dxe:SearchControl Name="search" Height="30" Width="200" Margin="38,0,362,270"/>
</Grid>
</Grid>
</UserControl>
This is with code-behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using EPOS.Desktop.ViewModel;
using EPOS.Desktop.View;
using EPOS.Desktop.Model;
using System.ComponentModel;
using DevExpress.Xpf.Editors;
using DevExpress.Xpf.LayoutControl;
namespace EPOS.Desktop.UserControls
{
/// <summary>
/// Interaction logic for QeueOrders.xaml
/// </summary>
public partial class QeueOrders : UserControl
{
public QeueOrders()
{
InitializeComponent();
DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(SearchControl.SearchTextProperty, typeof(SearchControl));
if (dpd != null)
{
dpd.AddValueChanged(search, OnSearchTextChanged);
}
}
private void OnSearchTextChanged(object sender, EventArgs e)
{
SearchControl tb = sender as SearchControl;
foreach (Tile t in tileLayoutControl.GetLogicalChildren(false))
{
if ((String.IsNullOrEmpty(tb.SearchText)) || (t.Content != null && t.Content.ToString().Contains(tb.SearchText)))
t.Visibility = Visibility.Visible;
else
t.Visibility = Visibility.Collapsed;
}
}
DemoViewModel demovm = new DemoViewModel();
private void Tile_Click(object sender, EventArgs e)
{
CategoryForm catform = new CategoryForm();
catform.ShowDialog();
}
}
}
But i want to do using MVVM patttern.
以上是关于列表视图中的WPF磁贴搜索的主要内容,如果未能解决你的问题,请参考以下文章
在 WPF 中重新排列列表框项目(如 Windows 8 开始屏幕磁贴)