If there’s a TextBlock inside a Grid, what’s the best way (performance wise) to set its width and height?
Is setting them in the TextBlock’s properties will be better than setting it as Grid’s properties?
basically what I’m asking is which one of the following is better :
<Grid Width="200" Height="200">
<TextBlock />
</Grid>
vs
<Grid>
<TextBlock Width="200" Height="200"/>
</Grid>
Using a Grid purely to constrain a TextBox is not really a good way to set the width of the TextBox. A Grid is more for laying out multiple controls. However this is perfectly acceptable:
This is along the same lines as what @Ahmed suggested.
Generally with a XAML layout the recommendation is to use a proportional layout rather than fixed sizes, so that your UI can be resized correctly with minimal oversight from any of your code. This means it is good to let the parent element dictate the size as much as possible, only used fixed sizes where you must. (Setting MinWidth/MaxWidth/etc is fine, just try to avoid explicitly setting Width where possible, the same goes for the Height properties).