Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - No CheckBox.CheckedChanged?

 
 
Old 01-31-2006   #1 (permalink)
RyanLeeSchneider


 
 

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
Old 01-31-2006   #2 (permalink)
RyanLeeSchneider


 
 

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
Old 01-31-2006   #3 (permalink)
Michael Latta


 
 

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
Old 01-31-2006   #4 (permalink)
RyanLeeSchneider


 
 

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
Old 01-31-2006   #5 (permalink)
Douglas Stockwell


 
 

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
 

Thread Tools


Similar Threads
Thread Forum
how to create checkbox using vbscript VB Script
Welcome Center - can't get rid of it (checkbox is missing!) Vista installation & setup
Welcome Center - can't get rid of it (checkbox is missing!) Vista General
Checkbox to never see this pop-up again. Vista account administration


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46