开发者

programatically set width of a column within a grid

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开发者_如何学JAVA 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


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)


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();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜