开发者

how do i insert a stack panel into a grid? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Can't create Columns in my WPF Grid. [Newbie]

i tried to insert the stack panel into grid using the following:

    <TabItem Header ="XML PARSING" Name="Tabitem5" Visibility="Visible">
        <Grid>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
                <StackPanel Name="stack1" Grid.Row="1" Grid.Column="0">
                    <Button Height="23" Name="Xmlap开发者_开发问答pendButton" Width="75" HorizontalAlignment="Right" Click="XmlappendButton_Click">Update</Button>
                </StackPanel>
        </Grid>
    </TabItem>

I can't seem to be able to load the design view after this. Any help is appreciated

EDIT: Sorry the error is: Error 1 A value of type 'ColumnDefinition' cannot be added to a collection or dictionary of type 'UIElementCollection'.


You are wrongly defining your columns and rows. You need to have your <ColumnDefinition />'s inside the the grid ColumnDefinitions property. You access that property through <Grid.ColumnDefinitions></Grid.ColumnDefinitions>. Apply the same logic for rows which have to be declared inside the Grid's RowDefinitions property. Here's the corrected sample:

<TabItem Header ="XML PARSING" Name="Tabitem5" Visibility="Visible">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition  Height="Auto"/>
            <RowDefinition  Height="Auto"/>
        </Grid.RowDefinitions>

                <StackPanel Name="stack1" Grid.Row="1" Grid.Column="0">
                    <Button Height="23" Name="XmlappendButton" Width="75" HorizontalAlignment="Right" Click="XmlappendButton_Click">Update</Button>
                </StackPanel>
    </Grid>
</Tabitem>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜