如何从用户输入和按钮事件中过滤列表视图?

时间:2015-03-16 04:36:31

标签: c# wpf xaml listview filter

所以我有一个使用list.items.add命令填充的Listview。我现在需要做的是创建两种类型的按钮。可以通过用户在文本框中输入的邮政编码过滤List,并仅显示具有该zip的属性。另一个需要“出售”该属性并将其从列表中删除。我已经搜索了高低,以便查找,但找不到任何与之相关的内容。

这是我的MainWindow.xaml.cs。

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;

namespace RealtorProgram
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }
    public class house
    {
        #region Properties
        public ulong AskingPrice
        {
            get;
            set;
        }
        public string Address
        {
            get;
            set;
        }
        public uint BedroomCount { get; set; }

        public ushort YearBuilt { get; set; }

        public uint SqFt { get; set; }

        public uint BathroomCount { get; set; }

        public decimal HOA { get; set; }

        public uint Zip { get; set; }

        public SoldChoices SoldStatus { get; set; }



        public void SetAsSold()
        {
            SoldStatus = SoldChoices.Sold;
        }


    }
        #endregion
    public class Apartment : house
    {
        public bool ArePetAllowed { get; set; }
        public int LeaseLengthMonths { get; set; }
        public LeaseChoices LeaseStatus { get; set; }
        public void SetAsLeased()
        {
            LeaseStatus = LeaseChoices.Leased;
        }

    }

    public class Condo : house
    {
        public int FloorNumber { get; set; }
        public int UnitNumber { get; set; }
        public bool CanBeOwned { get; set; }

    }

    public enum LeaseChoices
    {
        Leased,
        NotLeased

    }

    public enum SoldChoices
    {
        Sold,
        ForSale
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        HouseList.Items.Add(new house() { Address = "143 Bleach Ave", AskingPrice = 150000, BathroomCount = 2, BedroomCount = 2, SqFt = 1800, YearBuilt = 1953, HOA = 2500, Zip = 83685, SoldStatus = SoldChoices.ForSale });
        HouseList.Items.Add(new house() { Address ="4545 Programming Drive", AskingPrice = 1500000, BathroomCount = 10, BedroomCount = 12, SqFt = 9000, YearBuilt = 2005, HOA = 10000, Zip = 83719, SoldStatus = SoldChoices.ForSale });
        HouseList.Items.Add(new house() { Address = "101101 Binary Lane", AskingPrice = 170000, BathroomCount = 3, BedroomCount = 4, SqFt = 2500, YearBuilt = 1995, HOA = 5000, Zip = 83719, SoldStatus = SoldChoices.ForSale });
        HouseList.Items.Add(new house() { Address = "1000 Prebuilt Circle", AskingPrice = 100000, BathroomCount = 2, BedroomCount = 2, SqFt = 1350, YearBuilt = 1990, HOA = 1000, Zip = 83718, SoldStatus = SoldChoices.ForSale });
        HouseList.Items.Add(new house() { Address = "1024 East Logana Street", AskingPrice = 550000, BathroomCount = 7, BedroomCount = 7, SqFt = 4500, YearBuilt = 1921, HOA = 3300, Zip = 83718, SoldStatus = SoldChoices.ForSale });
        HouseList.Items.Add(new house() { Address = "8675 Silicon Valley Drive", AskingPrice = 100001, BathroomCount = 2, BedroomCount = 3, SqFt = 1500, YearBuilt = 1980, HOA = 500, Zip = 83685, SoldStatus = SoldChoices.ForSale });
        HouseList.Items.Add(new house() { Address = "876 Industrial Circle", AskingPrice = 500000, BathroomCount = 6, BedroomCount = 5, SqFt = 3800, YearBuilt = 1975, HOA = 2800, Zip = 83718, SoldStatus = SoldChoices.ForSale });
        HouseList.Items.Add(new house() { Address = "3145 Pi Lane", AskingPrice = 350000, BathroomCount = 4, BedroomCount = 4, SqFt = 1800, YearBuilt = 1999, HOA = 1800, Zip = 83719, SoldStatus = SoldChoices.ForSale });
        HouseList.Items.Add(new house() { Address = "1234 Unimaginative Court", AskingPrice = 225000, BathroomCount = 3, BedroomCount = 3, SqFt = 2100, YearBuilt = 1985, HOA = 900, Zip = 90210, SoldStatus = SoldChoices.ForSale });
        HouseList.Items.Add(new house() { Address = "3333 Middleoftheocean Circle", AskingPrice = 1500000000, BathroomCount = 25, BedroomCount = 30, SqFt = 30000, YearBuilt = 2002, HOA = 100000, Zip = 90210, SoldStatus = SoldChoices.ForSale });
        HouseList.Items.Add(new Apartment() { Address = "2455 Hilton Ave", AskingPrice = 150000, BathroomCount = 2, BedroomCount = 2, Zip = 83685, SqFt = 2000, YearBuilt = 2015, HOA = 1500, LeaseLengthMonths = 18, ArePetAllowed = false, LeaseStatus = LeaseChoices.NotLeased,SoldStatus= SoldChoices.ForSale });
        HouseList.Items.Add(new Apartment() { Address = "2455 Hilton Ave", AskingPrice = 250000, BathroomCount = 4, BedroomCount = 4, Zip = 83685, SqFt = 3850, YearBuilt = 2015, HOA = 2000, LeaseLengthMonths = 24, ArePetAllowed = true, LeaseStatus = LeaseChoices.NotLeased, SoldStatus= SoldChoices.ForSale });
        HouseList.Items.Add(new Condo() { Address = "1818 Condo Way", AskingPrice = 1000000, BathroomCount = 15, BedroomCount = 8, SqFt = 8000, YearBuilt = 2082, HOA = 1, Zip = 90210, FloorNumber = 13, UnitNumber = 1776, CanBeOwned = true, SoldStatus = SoldChoices.ForSale });
        HouseList.Items.Add(new Condo() { Address = "1818 Condo Way", AskingPrice = 500000, BathroomCount = 8, BedroomCount = 6, SqFt = 4500, YearBuilt = 2082, HOA = 2000, Zip = 90210, FloorNumber = 12, UnitNumber = 1408, CanBeOwned = true, SoldStatus = SoldChoices.ForSale });
        HouseList.Items.Add(new Condo() { Address = "1818 Condo Way", AskingPrice = 1000, BathroomCount = 3, BedroomCount = 1, SqFt = 450, YearBuilt = 2082, HOA = 10, Zip = 90210, FloorNumber = 2, UnitNumber = 5, CanBeOwned = true, SoldStatus = SoldChoices.ForSale });
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        int ZipCode;

        ZipCode = int.Parse(TextBox.Text);

        if (ZipCode == 83719                        






    }


}
}

这是我的Xaml

    <Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:RealtorProgram" x:Class="RealtorProgram.MainWindow"
Title="MainWindow" Loaded="Window_Loaded" Height="665.508">
<Grid Margin="0,0,122,367">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="515*"/>
        <ColumnDefinition Width="2*"/>
    </Grid.ColumnDefinitions>
    <ListView x:Name="HouseList" Margin="10,67,-122,-333" Grid.ColumnSpan="2" RenderTransformOrigin="0.482,0.389"  >
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Address" Width="Auto" DisplayMemberBinding="{Binding Address}"/>
                <GridViewColumn Header="Asking Price" Width="Auto" DisplayMemberBinding="{Binding AskingPrice}"/>
                <GridViewColumn Header=" Bedrooms" Width="Auto" DisplayMemberBinding="{Binding BedroomCount}"/>
                <GridViewColumn Header="Bathrooms" Width="Auto" DisplayMemberBinding="{Binding BathroomCount}"/>
                <GridViewColumn Header="Square Footage" Width="Auto" DisplayMemberBinding="{Binding Sqft}"/>
                <GridViewColumn Header="HOA" Width="Auto" DisplayMemberBinding="{Binding HOA}"/>
                <GridViewColumn Header="Zip Code" Width="Auto" DisplayMemberBinding="{Binding Zip}"/>
                <GridViewColumn Header="Sold Status" Width="Auto" DisplayMemberBinding="{Binding SoldStatus}"/>
                <GridViewColumn Header="Lease" Width="Auto" DisplayMemberBinding="{Binding LeaseLengthMonths}"/>
                <GridViewColumn Header="Pets"  Width="Auto" DisplayMemberBinding="{Binding ArePetAllowed}"/>
                <GridViewColumn Header="Floor" Width="Auto" DisplayMemberBinding="{Binding FloorNumber}"/>
                <GridViewColumn Header="Unit" Width="Auto" DisplayMemberBinding="{Binding UnitNumber}"/>
                <GridViewColumn Header="Can be Owned" Width="Auto" DisplayMemberBinding="{Binding CanBeOwned}"/>

            </GridView>
        </ListView.View>
    </ListView>
    <TextBox HorizontalAlignment="Left" x:Name="TextBox" Height="23" Margin="114,23,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
    <Button Content="Filter" HorizontalAlignment="Left" Margin="261,23,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click" />



</Grid>
</Window>

我将非常感谢任何关于我可以做什么的输入,以便让我的按钮点击事件过滤它们以及如何删除它们。

0 个答案:

没有答案