Alpha Omega

Alpha Omega

  • NA
  • 1
  • 2.2k

TextProperty OnTextChanged ändert nicht den Text

May 23 2013 11:05 AM
 Hallo Liebe Leute,

...OnTextChanged wird natürlich ausgelöst und die TextProperty bekommt einen neuen Wert scheint so aber der neue Wert wird nicht angezeigt:

XAML
<Window x:Class="WpfApplication5.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid Name="grid1" >
        <Grid.RowDefinitions>
            <RowDefinition Name="row0"/>
            <RowDefinition Name="row1"/>
        </Grid.RowDefinitions>
        <Button Margin=" 5" Click="HandleButtonClick"
                 Content="Wieviel Uhr ist es ? " />
        <TextBox HorizontalAlignment="Left" Height="116"
                 Margin="85,10,0,0" Grid.Row="1" TextWrapping="Wrap"
                  Name="txt" 
                 VerticalAlignment="Top" Width="333"/>
    </Grid>

    <x:Code>
        <![CDATA[
       
       
       
        ]]>
    </x:Code>
</Window>


C#:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
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 WpfApplication5
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {


        public MainWindow()
        {

            InitializeComponent();

            DependencyPropertyDescriptor descriptor =
          DependencyPropertyDescriptor.FromProperty(
              TextBox.TextProperty, typeof(TextBox));

            descriptor.AddValueChanged(txt, OnTextChanged);
            //ThreadPool.QueueUserWorkItem((state) =>
            //{
            //    Thread.Sleep(1000);

            //    // do your work here
            //    // CAUTION: use Invoke where necessary
            //});

        }
       
        void HandleButtonClick(object sender, RoutedEventArgs e)
        {

            txt.Text = string.Format("Es ist {0:HH:mm:ss} Uhr.", DateTime.Now);

        }

        public void OnTextChanged(object sender, EventArgs e)
        {
          

            txt.Text = string.Format("Es ist {0:HH:mm:ss} Uhr.", DateTime.Now  );
        

        }


    }
}



Soll ich Threads hier verwenden ?