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 Tutorial - WPF Lookless control that inherits ComboBox - IsEditable problem

 
 
Old 03-17-2009   #1 (permalink)
scarfinv
Guest


 
 

WPF Lookless control that inherits ComboBox - IsEditable problem

I've built a "lookless" control that inherits ComboBox. It has three
dependancy properties (CountryCode, Label, and ListByName), and a ReadOnly
property of DistrictList.

Whenever CountryCode changes, the Label is changed, and the DistrictList is
rebuilt. (eg. Country changes from CAN to USA, Label will change from
Province to State, and the list contents will change from provinces to
states). When the ListByName property changes, the items in the list will
flip from names, to two character codes, or back again (eg. Ontario to ON, or
ON to Ontario).

In my Generic.xaml file, the ControlTemplate uses a dockpanel that contains
a label and a combobox. I've bound the label Content property to the control
Label property, and I've bound the combobox ItemSource to the control
DistrictList property.

So far so good... I can flip between CAN and USA, and the control flips
between provinces and states.

However, I also want to support a country of "Other", and when that country
is chosen, the DistrictList that gets built is empty. So after building the
list, I check its Count property. If it is 0, I set IsEditable to True, else
I set it to False. That way, when there are no items in the list, the user
can type something in, but when there are items in the list, the user can't
type something in and must select something.

Changing the ComboBox's editable state is the part I can't seem to get
working.

I have subs that fire when the CountryCode and ListByName depedancy
properties change. Inside those subs they call a private method called
LoadDistrictList. That is the method that fills the private member variable
for the DistrictList property, and that sets IsEditable to true or false.

I was ablet o get this working by creating a new dependency property called
MyIsEditable (and MyIsEditableProperty). I then added IsEditable="{Binding
Path=MyIsEditable,RelativeSource={RelativeSource TemplatedParent}}" to the
combobox in my Generic.xaml for my control. (I also did the same for
IsReadOnly.)

Could someone explain why I can't use the IsEditable (and IsReadOnly)
property on my control (inherited from ComboBox), directly?


My System SpecsSystem Spec
 

Thread Tools



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