2

Is it possible to set the width of a column for Grid within Silverlight? I have a grid (not a grid view) with two columns. ColumnA and ColumnB. What I am trying to accomplish is when a user clicks on a button within ColumnA the width of ColumnA is set to .01. ColumnB should then expand the entire width of the grid to fill the remaining area. Similar to how you pin or un-pin a dock panel?

Is this the best approach or should I revert back to a dockpanel and let SL handle it? I'd prefer to manage it myself vs. using a RAD control as I think it is a little bloated for such a small and seemingly simple task.

Another thought I had was to use a gridsplitter but I was unsure as to how to programmatically collapse or expand the column using the gridsplitter? Hence my current predicament. Any suggestions would be greatly appreciated.

Thanks in advance

1
  • please share your xaml only grid area Commented Apr 13, 2011 at 21:48

2 Answers 2

10

Give your ColumnDefinition a name via the Name attribute, e.g.:

<ColumnDefinition Width="100" Name="FooColumn"/>

Then you can assign it a new Width in code whenever you want:

FooColumn.Width = new GridLength(1);

(edit: should have used the same name in both places... oops.. you get the idea though)

Sign up to request clarification or add additional context in comments.

Comments

0
Try this

<Grid x:Name="LayoutRoot" Background="White" ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>       
        <sdk:GridSplitter  />    
    </Grid>

 LayoutRoot.ColumnDefinitions.First().Width = new GridLength();

1 Comment

Thanks for your suggestions. When using .First it seems to override both columns and I "loose" the content in the second column?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.