noesis_user
Topic Author
Posts: 14
Joined: 08 May 2014, 00:04

TextBlock Text change event

22 Jan 2015, 22:00

Hi,

I have a text block and I need to capture its text change event to do certain things.

XAML:
    	<TextBlock x:Name="TextBoxToothNumber" HorizontalAlignment="Right" Height="23" TextWrapping="Wrap"   
         VerticalAlignment="Top" Width="54" FontSize="16" Margin="0,15,10,0" Background="{x:Null}" 
         Foreground="White" FontWeight="Normal" Text="{Binding SimpleText}"/>
Code:
        TextBoxDataModel* t_ = new TextBoxDataModel();
        Binding* b = new Binding("SimpleText");
        b->SetSource(t_);
        BindingOperations::SetBinding( tooth_number_block, TextBlock::TextProperty, b);
TextBoxDataModel class:
    class TextBoxDataModel: public Noesis::Core::BaseComponent,
                        public Noesis::Gui::INotifyPropertyChange
    {
    
    public:
       TextBoxDataModel() : _simpleText("yay")
        { }
    
      ~TextBoxDataModel()
       {}
    
      const NsChar* GetSimpleText() const
      {
        return _simpleText;
      }
    
      void SetSimpleText(const NsChar* simpleText)
      {
        if (_simpleText != simpleText)
        {
            _simpleText = simpleText;
            _changedEvent(this, NSS(SimpleText));
        }
      }
   
      /// From INotifyPropertyChange
      //@{
      PropertyChangedEvent& PropertyChanged()
      {
        return _changedEvent;
      }
    
      DestroyedDelegate& Destroyed()
      {
        return _destroyedEvent;
      }
      //@}
    
    
    private:
      const NsChar* _simpleText;
   
      PropertyChangedEvent _changedEvent;
      DestroyedDelegate _destroyedEvent;
    
      NS_IMPLEMENT_INLINE_REFLECTION(TextBoxDataModel, BaseComponent)
      {
        NsMeta<Noesis::Core::TypeId>("TextBoxDataModel");
        NsImpl<INotifyPropertyChange>();
        
        NsProp("SimpleText", &TextBoxDataModel::GetSimpleText, &TextBoxDataModel::SetSimpleText);
      }
    };
But still I don't get notified when text changes in textBlock. What am I missing?

Thanks.
 
User avatar
sfernandez
Site Admin
Posts: 3188
Joined: 22 Dec 2011, 19:20

Re: TextBlock Text change event

23 Jan 2015, 18:21

The TextBlock class doesn't define a TextChanged event, maybe you want to use a TextBox control:
<TextBox x:Name="TextBoxToothNumber" HorizontalAlignment="Right" Height="23" TextWrapping="Wrap"   
         VerticalAlignment="Top" Width="54" FontSize="16" Margin="0,15,10,0" Background="{x:Null}" 
         Foreground="White" FontWeight="Normal" Text="{Binding SimpleText}"/>
Have you tried this way?

Who is online

Users browsing this forum: Bing [Bot] and 3 guests