WPF layout, can I clean this up?
Just fyi, I am new to WPF.
I am creating a sidebar in my WPF app and want rounded corners. Which I learned is not a property you can attach to a Grid. Also, I tried putting the textblocks in the border control, but the error message I got back said, "Child can only be set once".
Below is the code I have so far, but I don't like having to nest my textblocks in a stackpanel, that is nested in a grid, that is nested in a border, that is nested in the parent Grid. Any way to clean this up? (if not, no worries, again, kind of new to this, and just looking to get my xaml as organized as possible)
<Grid Style="{StaticResource SideBar}">
<Border Style="{StaticResource RoundedSidebar}">
<Grid>
<StackPanel Orientation="Vertical" VerticalAlignment="Top">
<TextBlock />
<TextBlock />
<TextBlock />
</StackPanel>
</Grid>
</Border>
</Grid>
Any feedback would be greatly apprecia开发者_开发知识库ted.
Thanks
If you don't have any elements other than the border in that outter Grid element, you can remove that for starters.
Also, the way you have your border now, with that StackPanel being the only element of the Grid inside the border, you can remove that Grid as well...
Finally, you don't need the Orientation property set because Vertical is the default and it is perfectly normal to stack TextBlocks and other elements within a StackPanel, it is its purpose after all...
There is not much to clean up. Here is what I would do:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Border Style="{StaticResource RoundedSidebar}" Grid.Column="1">
<StackPanel Orientation="Vertical" VerticalAlignment="Top">
<TextBlock />
<TextBlock />
<TextBlock />
</StackPanel>
</Border>
</Grid>
精彩评论