开发者

Silverlight: Data Binding: Using of Dependency Properties within a Row of a Collection

开发者 https://www.devze.com 2023-03-08 17:54 出处:网络
I have an collection + its structure: public class FunctionListBindStructure : AttributeBase { public FunctionListBindStructure() : base(true) {}

I have an collection + its structure:

 public class FunctionListBindStructure : AttributeBase
{
    public FunctionListBindStructure() : base(true) {  }

    //this represents one row of the collection
    public MyFunction Function { get; set; }
    public string Name { get; set; }

}

public class FunctionListBind : AttributeListBase
{
    //this represents 
    public ObservableCollection<FunctionListBindStructure> FunctionList { get; set; }

    public FunctionListBind()
        : base(true)
    {
        FunctionList = new ObservableCollection<FunctionListBindStructure>();
    }

    public override IList GetList()
    {
        return FunctionList as IList;
    }
}

This class makes usage of a framework, which generates a Dependency Property for the CLR property Function.DisplayName as "FunctionDisplayNameProperty".

In my example view I bind this collection to a ListBox

ListBox ItemsSource="{Binding MyModel.FunctionListBind.FunctionList}" Height="52" HorizontalAlignment="Left" Margin="136,157,0,0" Name="listBox1" VerticalAlignment="Top" Width="130" >
        <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                    <TextBlock Text="{Binding FunctionDisplayNameProperty,  Mode=TwoWay}"/>
            </StackPanel>
        </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

The problem is now that only the last item of the collection is displayed in the list...the previous items are rendered only with space; although I am开发者_开发百科 pretty sure (via debugger) that the dependendy properties (when they registered and their value set) of the previous rows shall have non-initial values. If I refer directly to the corresponding CLR property (Function.DisplayName) all works fine.

My question: Do I make here a design error? Are Dependency Properties not supposed to be used as a row type? I use the same pattern for non-collection and there it works. This is also the reason why I want to use the same approach for collections (I can use 90% of the exisitng codeline to generate and set the Dependeny Properties).

Thanks for any hints also how (if not a design error) to debug the Dependency Property binding.


It was just a bug of my framework coding. I have defined the dependency properties as an instance attribute, instead of a static one. Now all works fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消