चलिए इन कोडों को पढ़ते हैं, मैंने विंडोज फोन 8 प्रोजेक्ट में दो समान उपयोगकर्ता नियंत्रणों को परिभाषित किया है और मैं वास्तव में उनमें से कौन सा बेहतर होना चाहता हूं। मैंने प्रोफाइलिंग की जांच की है, ऐसा लगता है कि वे लगभग समान हैं।ग्रिड और स्टैकपैनेल, जिसमें बेहतर प्रदर्शन है?
उपयोगकर्ता नियंत्रण 1, मेरे लेआउट को डिजाइन करने के लिए ग्रिड की संपत्ति का उपयोग करके।
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}" Height="108">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Rectangle Grid.RowSpan="2" Grid.Row="0" Height="108" Width="54" Fill="Blue"></Rectangle>
<TextBlock Grid.Row="0" Grid.Column="1" Text="Caption" Style="{StaticResource PhoneTextExtraLargeStyle}"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="1" Text="URLURLURLURLURLURL" Style="{StaticResource PhoneTextSmallStyle}"></TextBlock>
</Grid>
उपयोगकर्ता नियंत्रण 2, मेरे लेआउट को डिजाइन करने के लिए StackPanel का उपयोग कर।
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}" Height="108">
<StackPanel Orientation="Horizontal">
<Rectangle Height="108" Width="54" Fill="Red"></Rectangle>
<StackPanel Orientation="Vertical">
<TextBlock Text="Caption" Style="{StaticResource PhoneTextExtraLargeStyle}"></TextBlock>
<TextBlock Text="URLURLURLURLURLURL" Style="{StaticResource PhoneTextSmallStyle}"></TextBlock>
</StackPanel>
</StackPanel>
</Grid>
ऐसा लगता है कि मूल लेआउट समान है। लेकिन जब मैं विजुअलाइजिंग पेड़ का विश्लेषण करने के लिए एक्सएएमएल जासूस का उपयोग करता हूं, तो UserControl 1 में कम नोड्स होते हैं, लेकिन इसकी थोड़ी अधिक मेमोरी होती है। क्यूं कर?
धन्यवाद अधिक वस्तुओं शामिल हैं! – Eddie