Results 1 to 3 of 3

Thread: Binding to a Function

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2011
    Posts
    1

    Binding to a Function

    Hello, I am trying to develop a window (WPF) that will collect data in a single textbox. The textblock will say “please enter the minimum value: “and the user hits enter I than want the textblock to change to “please enter the maximum value” I know this is done by data binding. The way I understand it is that the Enter button will increment i by some value, which is being passed into a function. Where the functions output is data bound to the textblock. I know you can sort the data collection by maximum and minimum, but I need that type of layout mentioned above. So I guess my question is it possible to data bind to a function, or is there some other way that I not seeing? Thanks for the help/suggestions/tips

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Binding to a Function

    No, it's only possible to bind to properties.

    If you're talking about binding the Button so that it does something when it's clicked without handling its Click event, that can be done using properties. The Button implements the ICommandSource interface, which means that it has a Command property that can be bound to a property whose type implements the ICommand interface. That ICommand object has an Execute method that can do as you like. When the Button is clicked, the Execute method of the bound object is called.

    If you're talking about binding the TextBlock then I'd probably suggest binding it to a property of type String and then, when the Button is clicked, modifying the value of that property. You'll probably also want to raise a PropertyChanged event for that property so that the UI knows to update, otherwise you'll have to update the binding explicitly.

    By the way, this site has a forum dedicated to WPF. I've asked the mods to move this thread there.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Binding to a Function

    Moved to the WPF Forum.

    Thanks for the report John

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width