tags:

views:

1321

answers:

2

The only example I can think of is in html - if you dynamically add a TR w/ a colspan + div inside it containing details (editable) on the click of the previous TR for example

I'm trying to grok XAML and wanted to see if someone could point me in the right direction w/ this wacky request.

A: 

What UIelement are you looking at in WPF? The answer will depend on what you're working with :)

volatilsis
I'm not sure to be honest, A grid of some type would be my first attempt
Toran Billups
+2  A: 

Here is something, not sure if it is what you are looking for:

XAML:

<Grid Name="_mainGrid">
    <Grid.ColumnDefinitions>
        <!-- Contains the button -->
        <ColumnDefinition Width="Auto"/>
        <!-- Contains the edit control -->
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <!-- So that we have the 'empty' space at the end -->
        <RowDefinition Height="*"/> 
    </Grid.RowDefinitions>
</Grid>

Code:

    public Window1()
    {
        InitializeComponent();
        CreateRow(); // Bootstrap
    }

    private void CreateRow()
    {
        RowDefinition newRow = new RowDefinition();
        newRow.Height = new GridLength(0, GridUnitType.Auto);
        _mainGrid.RowDefinitions.Insert(_mainGrid.RowDefinitions.Count - 1, newRow);

        int rowIndex = _mainGrid.RowDefinitions.Count - 2;

        UIElement editControl = CreateEditControl();
        Grid.SetRow(editControl, rowIndex);
        Grid.SetColumn(editControl, 1);
        Grid.SetRowSpan(editControl, 1);
        Grid.SetColumnSpan(editControl, 1); // Change this if you want.
        _mainGrid.Children.Add(editControl);

        Button addButton = new Button();
        addButton.Content = "Add";
        addButton.Click += new RoutedEventHandler(b_Click);
        Grid.SetRow(addButton, rowIndex);
        Grid.SetColumn(addButton, 0);
        _mainGrid.Children.Add(addButton);
        addButton.Tag = editControl;

    }

    void b_Click(object sender, RoutedEventArgs e)
    {
        CreateRow();
        Control button = (Control)sender;
        UIElement editControl = (UIElement)button.Tag;
        _mainGrid.Children.Remove(button);
        Grid.SetColumn(editControl, 0);
        Grid.SetColumnSpan(editControl, 2);
    }

    private UIElement CreateEditControl()
    {
        return new TextBox();
    }
Jonathan C Dickinson
Let me work up a quick poc to test this code and i'll accept an answer when I see something working ;)
Toran Billups