views:

547

answers:

2

I'm writing a ChecklistBox control, which is a listbox that renders CheckBoxes inside the list. I'm then using this control inside of a DataForm's EditTemplate. Along with this control, I've got two text boxes that are bound to properties of the DataContext of the Dataform.

For reference, the ChecklistBox has three implemented properties...

  • ItemsSource -> the list of possible items to have for the collection on your object.
  • ObjectCollection -> the collection of objects that should be affected... think your order details in this scenario.
  • CheckboxContentTemplate -> this is what should be shown next to the checkbox in the list (typically, this is just the text of the object, but it could be anything.)

What I'm running into is that the Dataform's Commit button won't activate when I change the ObjectCollection. However, if I change the text of either textbox in the edittemplate during the execution of the program, my Commit button activates.

Any ideas?


@Shawn:

I have two objects, Users & Roles...

public class Users : INotifyPropertyChanged, IEditableObject
{
public string firstname {get{...}set{...}}
public string lastname {get{...}set{...}}
public RoleCollection Roles {get{...}set{...}}
}

public class Role : INotifyPropertyChanged, IEditableObject
{
public Guid Oid {get{...}set{...}}
public string Code {get{...}set{...}}
public string Name {get{...}set{...}}
public string Description{get{...}set{...}}
}

public class RoleCollection:BulkObservableCollection<Role>
{
}

public class BulkObservableCollection<T>:ObservableCollection<T>
{
public void AddRange(IList toAdd)
{
...
}
}

let's say for arguement's sake that the above code has all the proper structure to handle the events in INotifyPropertyChanged and IEditableObject. When I go and build the checklistbox, I'm looking at the ObjectCollection ("user".Roles.Where(item => Item.Oid == role.Oid).Count > 0;) to say whether or not to initially check the checkbox or not.

I know for fact that when I uncheck and check the boxes, the "DataContext" of the role is being added or removed from the object, as I traced it out. I'd like to somehow alert the dataform that when I remove an object from "Roles", that it is altering the object.

I tried capturing the CollectionChanged event from ObservableCollection, and then firing off a "PropertyChanged("Roles")" event, but that didn't seem to solve it.

+1  A: 

The DataForm assumes a single object not a collection for the commit button. Can you explain your bound data a little clearer?

It may be that in your AddRange yuo are not using the INotifyCollectionChanged interface right? (can't tell from the example). Otherwise it looks like you're doing the right thing.

Shawn Wildermuth
i explained further above. Does this give you enough to go on?Thx.
Richard B
I have a similar problem, but I am using collection, so that is probably my issue... a pity because that's what I want.
Grayson Mitchell
A: 

I have similar issue.

When I'm trying to bind ObservableCollection<> to DataField, everything works fine, but when I'm changing something in this collection the Commit and Cancel buttons are still not active.

Object that I'm trying to bind:

    [DataMember]
    [CustomValidation(typeof(TaskDFItemValidator), "ValidateResources")]
    public ObservableCollection<ResourceCBItem> ResourcesDF
    {
        get { return resourcesDF; }
        set
        {
            ValidationContext context = new ValidationContext(this, null, null);
            context.MemberName = "ResourcesDF";
            Validator.ValidateProperty(value, context);
            resourcesDF = value;
            this.OnPropertyChanged("ResourcesDF");
        }
    }

XAML:

<dataFormToolkit:DataField x:Name="ResourcesDF" Label="Resources" LabelStyle="{StaticResource DataFieldLabel}">
<ListBox x:Name="ResourcesLB" MaxHeight="100" TabIndex="6" IsTabStop="True" 
         ItemsSource="{Binding ResourcesDF, Mode=TwoWay}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <CheckBox Content="{Binding ResourceFullName}" Tag="{Binding Resource.EmployeeId}" 
             IsChecked="{Binding IsChecked, Mode=TwoWay}" Click="CheckBox_Click" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

Does anyone know how to solve it?

gorczas

related questions