为什么我的C#WPF文本框TextChanged无法启动? [英] Why doesn't my C# WPF textbox TextChanged fire?

查看:132
本文介绍了为什么我的C#WPF文本框TextChanged无法启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我的C#WPF文本框的TextChanged事件没有触发.

Hi My C# WPF textbox''s TextChanged event doesn''t fire.

<Window x:Class="InfoManager.Presentation_Layer.WindowTagAttaching"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="WindowTagAttaching" Height="300" Width="300">
    <Grid>
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="28,31,0,0" Name="textBlock1" Text="Filter Tags:" VerticalAlignment="Top" />
        <TextBox Text="{Binding Path=FilterText,Mode=TwoWay}"  Height="23" HorizontalAlignment="Left" Margin="91,28,0,0" Name="textBoxFilterTags" VerticalAlignment="Top" Width="120" TextChanged="textBoxFilterTags_TextChanged" />
        <ListBox ItemsSource="{Binding Path=Filter,UpdateSourceTrigger=Explicit}"  Height="178" HorizontalAlignment="Left" Margin="12,71,0,0" Name="listBoxTags" VerticalAlignment="Top" Width="254">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <CheckBox IsChecked="{Binding Path=Tick,Mode=TwoWay}" Margin="3,1,1,1" />
                        <TextBlock Text="{Binding Path=Name}" Margin="3,1,1,1" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>




和CLR代码:




and CLR code:

using System.Text;
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.Shapes;
using InfoManager.BLL;
using System.Collections.ObjectModel;

namespace InfoManager.Presentation_Layer

    public partial class WindowTagAttaching : Window
    {
        TagEditor tagEditor;
        public WindowTagAttaching(InfoItem infoItem, TotalTagFamilyCollection totalTagFamilyCollection)
        {
            InitializeComponent();
            tagEditor = new TagEditor(infoItem, totalTagFamilyCollection);
            this.DataContext = tagEditor;
            
        }

        private void textBoxFilterTags_TextChanged(object sender, TextChangedEventArgs e)
        {// This event doesn't fire
            BindingExpression be = listBoxTags.GetBindingExpression(ListBox.ItemsSourceProperty);
            be.UpdateSource();
        }

    }

}

推荐答案

代码中没有发现问题,应该可以使用.
No issue found in the code, it should work.


这篇关于为什么我的C#WPF文本框TextChanged无法启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆