第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在多種條件下過濾不起作用

在多種條件下過濾不起作用

C#
BIG陽 2021-10-31 19:59:03
我正在編寫一個將虛擬數(shù)據(jù)加載到數(shù)據(jù)網(wǎng)格的 WPF 應用程序。數(shù)據(jù)網(wǎng)格包含以下數(shù)據(jù)模型:public class CharacterCollection  {    public string Name { get; set; }    public int Level { get; set; }    public string Race { get; set; }    public string Class { get; set; }    public List<CharacterCollection> GetCharacters()    {      List<CharacterCollection> characters = new List<CharacterCollection>();      characters.Add(new CharacterCollection { Name = "Lothar", Class = "Fighter", Race = "Human", Level = 5 });      characters.Add(new CharacterCollection { Name = "Turk", Class = "Barbarian", Race = "Half-Orc", Level = 3 });      characters.Add(new CharacterCollection { Name = "Melian", Class = "Cleric", Race = "Elf", Level = 10 });      //... there's about 16 more entries, but you get the idea ;)      return characters;    }接下來,我添加了 4 個組合框;每個都填充了 CharacterCollection 中的一個屬性public partial class MainWindow : Window{    private CharacterCollection _characters = new CharacterCollection();    List<CharacterCollection> collection = new List<CharacterCollection>();    public MainWindow()    {      InitializeComponent();      collection = _characters.GetCharacters();      dgCharacterChart.ItemsSource = collection;      var characterNames = collection.Select(c =>c.Name).Distinct().ToList();      foreach(var item in characterNames)      {        CheckBox cb = new CheckBox();        cb.Content = item.ToString();        cbName.Items.Add(cb);      }      //...the other 3 combo boxes are filled the same way. I know its ugly and I will work on abstracting this a little better :)   }}到目前為止,我得到的是 4 個組合框,其中填充了復選框,用戶可以根據(jù)需要進行檢查。這些將用于過濾。當我單擊僅選擇一個字段的按鈕時,例如從“名稱”組合框中,它過濾得很好。但是,如果我從Name 中選擇了多個,或者如果我開始檢查其他組合框中的多個條目,則我的數(shù)據(jù)網(wǎng)格顯示為空白。當我調(diào)試我的代碼時,我可以看到我的謂詞列表包含我所有標記為已檢查的條目,但我的集合計數(shù)為 0。有人可以幫我弄清楚為什么我會得到這些結(jié)果嗎?
查看完整描述

1 回答

?
MYYA

TA貢獻1868條經(jīng)驗 獲得超4個贊

我做了類似的事情,但我通過文本框過濾。也許它會幫助你。


.Xaml 如下


 <TextBox FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}"

                                     Background="{x:Null}"

                                     Text="{Binding Item , UpdateSourceTrigger=LostFocus}" Margin="6,0,0,0" BorderThickness="0" PreviewKeyDown="ItemField_PreviewKeyDown" TextChanged="ItemField_TextChanged" IsReadOnly="{Binding IsReadonly}" />

.Xaml.cs 如下


private ObservableCollection<ItemGrid> _itemGrid = new ObservableCollection<ItemGrid>();

    public ObservableCollection<ItemGrid> ItemGrid

    {

        get

        {

            return _itemGrid;

        }

        set

        {

            _itemGrid = value;



        }

    }


    private void ItemField_TextChanged(object sender, TextChangedEventArgs e)

    {

        if (isBeginingEdit) return;

        //here we show the item selector and take care of autocomplete

        var textBox = sender as TextBox;

        if (textBox.Text != "")

        {

            var _itemSourceList = new CollectionViewSource() { Source = ItemGrid };

            ICollectionView Itemlist = _itemSourceList.View;

            ItemSearchText = textBox.Text;

            Itemlist.Filter = ItemFilter;

            var count = _itemSourceList.View.Cast<ItemGrid>().Count();

            if (count > 0)

            {

                ItemsGrid.ItemsSource = Itemlist;

            } 

        } 

   }


查看完整回答
反對 回復 2021-10-31
  • 1 回答
  • 0 關(guān)注
  • 216 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號