Windows Vista Forums

No CheckBox.CheckedChanged?
  1. #1


    RyanLeeSchneider Guest

    No CheckBox.CheckedChanged?


    It'd be nice if CheckBox had a CheckedChanged eventhandler instead of/in
    addition to the two separate Checked and Unchecked events.



      My System SpecsSystem Spec

  2. #2


    RyanLeeSchneider Guest

    Re: No CheckBox.CheckedChanged?


    You lost me, wouldn't the binding go the other way? (e.g. if I changed the
    bound property the checkbox's checked state would change)

    "Michael Latta" wrote:

    > You can bind to the IsChecked property to get a method called with the
    > current value of the IsChecked property whenever it changes.
    >
    > Michael
    > (C# / WPF MVP)
    > http://spaces.msn.com/members/michaellatta
    >
    > "RyanLeeSchneider" <RyanLeeSchneider@discussions.microsoft.com> wrote in
    > message news:C74B1151-EE56-40BF-87CD-D91D3732DE27@microsoft.com...
    > >
    > > It'd be nice if CheckBox had a CheckedChanged eventhandler instead of/in
    > > addition to the two separate Checked and Unchecked events.

    >
    >
    >


      My System SpecsSystem Spec

  3. #3


    Michael Latta Guest

    Re: No CheckBox.CheckedChanged?

    You can create a property that is bound to the IsChecked property of the
    control. When the user checks the check box your property setter will be
    invoked for bi-directional binding. You can place in the setter either your
    logic or a call to a method that will respond to the changes in state.

    Michael
    (C#/WPF MVP)
    http://spaces.msn.com/members/michaellatta

    "RyanLeeSchneider" <RyanLeeSchneider@discussions.microsoft.com> wrote in
    message news:A0AC8F75-F099-4E0A-B25A-15EF5A6ED928@microsoft.com...
    >
    > You lost me, wouldn't the binding go the other way? (e.g. if I changed the
    > bound property the checkbox's checked state would change)
    >
    > "Michael Latta" wrote:
    >
    >> You can bind to the IsChecked property to get a method called with the
    >> current value of the IsChecked property whenever it changes.
    >>
    >> Michael
    >> (C# / WPF MVP)
    >> http://spaces.msn.com/members/michaellatta
    >>
    >> "RyanLeeSchneider" <RyanLeeSchneider@discussions.microsoft.com> wrote in
    >> message news:C74B1151-EE56-40BF-87CD-D91D3732DE27@microsoft.com...
    >> >
    >> > It'd be nice if CheckBox had a CheckedChanged eventhandler instead
    >> > of/in
    >> > addition to the two separate Checked and Unchecked events.

    >>
    >>
    >>




      My System SpecsSystem Spec

  4. #4


    RyanLeeSchneider Guest

    Re: No CheckBox.CheckedChanged?


    What I don't like about that is then my data object has UI-specific code in
    it.

    In my scenario, I'm using checkboxes to 'select' nodes of a treeview for
    batch-processing. The caveat is that the data objects I am bound to don't
    (and cannot because they are used in other projects) have references to the
    WinFX runtime.

    I'd like to use style triggers to highlight the nodes (bold if all childern
    are selected, italics if some, normal if none) ala the WPF folder picker
    sample from okoboji. However, I don't want to clutter up my 'pure' data
    objects with UI-specific properties.

    What would people suggest in that scenario? Currently, I'm thinking of
    having a 'shadow' heirarchical data object that contains the UI-specific
    properties for my treeview, and use a separate datasource to bind things like
    my checkbox to that. Sound reasonable?

    "Michael Latta" wrote:

    > You can create a property that is bound to the IsChecked property of the
    > control. When the user checks the check box your property setter will be
    > invoked for bi-directional binding. You can place in the setter either your
    > logic or a call to a method that will respond to the changes in state.
    >
    > Michael
    > (C#/WPF MVP)
    > http://spaces.msn.com/members/michaellatta
    >
    > "RyanLeeSchneider" <RyanLeeSchneider@discussions.microsoft.com> wrote in
    > message news:A0AC8F75-F099-4E0A-B25A-15EF5A6ED928@microsoft.com...
    > >
    > > You lost me, wouldn't the binding go the other way? (e.g. if I changed the
    > > bound property the checkbox's checked state would change)
    > >
    > > "Michael Latta" wrote:
    > >
    > >> You can bind to the IsChecked property to get a method called with the
    > >> current value of the IsChecked property whenever it changes.
    > >>
    > >> Michael
    > >> (C# / WPF MVP)
    > >> http://spaces.msn.com/members/michaellatta
    > >>
    > >> "RyanLeeSchneider" <RyanLeeSchneider@discussions.microsoft.com> wrote in
    > >> message news:C74B1151-EE56-40BF-87CD-D91D3732DE27@microsoft.com...
    > >> >
    > >> > It'd be nice if CheckBox had a CheckedChanged eventhandler instead
    > >> > of/in
    > >> > addition to the two separate Checked and Unchecked events.
    > >>
    > >>
    > >>

    >
    >
    >


      My System SpecsSystem Spec

  5. #5


    Douglas Stockwell Guest

    Re: No CheckBox.CheckedChanged?

    I think what Michael was suggesting was something like this:

    class MyDataObject
    {
    public bool Selected
    {
    set { ... }
    }
    }

    <CheckBox IsChecked="{Binding Path=Selected, Mode=OneWayToSource}" />

    This doesn't place any dependencies to WPF in your model. But if you still
    want to keep this out of the model, then yes creating a shadow model is common
    practice. Effectively this is the ViewModel from the "Model View ViewModel"
    pattern that a few people have been throwing around.

    - Doug

    > What I don't like about that is then my data object has UI-specific
    > code in it.
    >
    > In my scenario, I'm using checkboxes to 'select' nodes of a treeview
    > for batch-processing. The caveat is that the data objects I am bound
    > to don't (and cannot because they are used in other projects) have
    > references to the WinFX runtime.
    >
    > I'd like to use style triggers to highlight the nodes (bold if all
    > childern are selected, italics if some, normal if none) ala the WPF
    > folder picker sample from okoboji. However, I don't want to clutter
    > up my 'pure' data objects with UI-specific properties.
    >
    > What would people suggest in that scenario? Currently, I'm thinking
    > of having a 'shadow' heirarchical data object that contains the
    > UI-specific properties for my treeview, and use a separate datasource
    > to bind things like my checkbox to that. Sound reasonable?
    >
    > "Michael Latta" wrote:
    >
    >> You can create a property that is bound to the IsChecked property of
    >> the control. When the user checks the check box your property setter
    >> will be invoked for bi-directional binding. You can place in the
    >> setter either your logic or a call to a method that will respond to
    >> the changes in state.
    >>
    >> Michael
    >> (C#/WPF MVP)
    >> http://spaces.msn.com/members/michaellatta
    >> "RyanLeeSchneider" <RyanLeeSchneider@discussions.microsoft.com> wrote
    >> in message news:A0AC8F75-F099-4E0A-B25A-15EF5A6ED928@microsoft.com...
    >>
    >>> You lost me, wouldn't the binding go the other way? (e.g. if I
    >>> changed the bound property the checkbox's checked state would
    >>> change)
    >>>
    >>> "Michael Latta" wrote:
    >>>
    >>>> You can bind to the IsChecked property to get a method called with
    >>>> the current value of the IsChecked property whenever it changes.
    >>>>
    >>>> Michael
    >>>> (C# / WPF MVP)
    >>>> http://spaces.msn.com/members/michaellatta
    >>>> "RyanLeeSchneider" <RyanLeeSchneider@discussions.microsoft.com>
    >>>> wrote in message
    >>>> news:C74B1151-EE56-40BF-87CD-D91D3732DE27@microsoft.com...
    >>>>
    >>>>> It'd be nice if CheckBox had a CheckedChanged eventhandler instead
    >>>>> of/in
    >>>>> addition to the two separate Checked and Unchecked events.




      My System SpecsSystem Spec

No CheckBox.CheckedChanged? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create checkbox using vbscript ramji VB Script 1 07 Sep 2008
Welcome Center - can't get rid of it (checkbox is missing!) William Dowell Vista installation & setup 1 23 Jul 2008
Check a checkbox with the space bar RF Avalon 2 26 May 2008
Checkbox to never see this pop-up again. Andrew Garttmeyer Vista account administration 1 26 Jul 2007
CheckBox groups Erno Avalon 2 05 Feb 2006