列表视图中的WPF磁贴搜索

问题描述 投票:-4回答:1
<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才有可能。如果您了解其他最佳方式,请分享解决方案。

wpf mvvm tile
1个回答
-1
投票
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.     
© www.soinside.com 2019 - 2024. All rights reserved.