views:

30

answers:

1

I have a class

public class Item
    {
        public string A { get; set; }
        public Control B { get; set; }
    }
I'm using MVVM with Silverlight. I have a custom view that is inherited from a standard view. Custom view has public property
public ICollection MyItems { get; set; }
which should store items described above. In xaml of my view I have
xxxx.MyItems>
    Item A="someText" B="_existingButton" />
    Item A="someText2" B="_existingButton2" />
/xxxx.MyItems>

Initialize() method of View fails when trying to assign value for B.

How can I assign a reference to existing element for a custom collection item?

A: 

I don't exactly understand what you are trying to achieve, but to help you arrive at a solution, I recommend that you attempt your task in the code behind file first (i.e. in the .xaml.cs) file.

By doing this, you will be given much more informative help from the compiler and intellisense.

Once you've achieved what you wanted in the code behind, then try and implement it in the xaml file.

Phillip Ngan
I created property on the view that contains a collection of custom objects. An item of a collection may contain a reference to an existing element on a view (see _existingButton in sample above). I have figured out how to create and fill the collection in XAML, but setting the reference to an existing element raises a XamlParseException AG_E_PARSER_BAD_PROPERTY_VALUE (the location is on B=" of the first item in a collection). How may I bind to an existing element, or defer binding in XAML in case _existingButton has not been created yet?
Kirill