开发者

Is there a use for XAML <ColumnDefinition>Something Here Example</ColumnDefinition>?

开发者 https://www.devze.com 2022-12-08 09:25 出处:网络
I was just creating a Grid in my XAML when i noticed that Visual Studio a开发者_StackOverflowutomatically creates ColumnDefinitions like this:

I was just creating a Grid in my XAML when i noticed that Visual Studio a开发者_StackOverflowutomatically creates ColumnDefinitions like this:

<Grid>
   <Grid.ColumnDefinitions>
      <ColumnDefinition></ColumnDefinition>
      <ColumnDefinition></ColumnDefinition>
   </Grid.ColumnDefinitions>
</Grid>

I always stop this from happening by using the shorthand but then wondered would there be any purpose for using the long hand equivalent; can you put anything in between these tags?

Thanks, Kohan.


Well, you could specify sub-properties using property element syntax, but I have no idea why you would:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition>
            <ColumnDefinition.Width>
                Auto
            </ColumnDefinition.Width>
        </ColumnDefinition>
    </Grid.ColumnDefinitions>

    <TextBlock>Hi</TextBlock>
</Grid>


Maybe if you wanted to use an attached property:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition>
            <mystuff:Adorners.Overlay>
                <TextBlock>I'm on top of the column!</TextBlock>
            <mystuff:Adorners.Overlay>
        </ColumnDefinition>
    </Grid.ColumnDefinitions>

    <TextBlock>Hi</TextBlock>
</Grid>

I haven't actually tried this it seems like it should work if you co a use case for it.

0

精彩评论

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

关注公众号