简体   繁体   中英

Send list of controls to UserControl

Hi i want to create control which will have configurable columns (something like dataGrid but with additional features). In xaml i want to have something like this:

<MyGrid ItemsSource="{Binding Orders}">
    <MyGrid.Columns>
        <MyGridTextColumn Header="Serial Number" Value="{Binding Id}" />
        <MyGridTextColumn Header="Customer" Value="{Binding Customer}" />
        <MyGridCheckBoxColumn Header="Is active" Value="{Binding IsActive}" />
    </MyGrid.Columns>
</MyGrid>

I've created in background code property with list of object, i've tried a lot of things but setter is never run.

public partial class MyGrid : UserControl
{

    private List<Object> _columns;
    public List<Object> Columns
    {
        get { return _columns; }
        set
        {
            _columns = value;
        }
    }
}

Is this something else i need to do to add these property? I also tried with DependencyProperty but it also does not work.

Have in mind that the setter will be called when creating the List of columns not when filling it with columns.

The xaml

<MyGrid.Columns>
    <MyGridTextColumn Header="Serial Number" Value="{Binding Id}" />
    <MyGridTextColumn Header="Customer" Value="{Binding Customer}" />
    <MyGridCheckBoxColumn Header="Is active" Value="{Binding IsActive}" />
</MyGrid.Columns>

just adds columns to an existing collection, does not create a new one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM