2012-07-23 9 views
12

VariableSizedWrapGrid और WrapGrid दोनों अजीब मापने हैं - वे पहले आइटम के आधार पर सभी बच्चों को मापते हैं।वेरिएबल साइज्डवापग्रीड और रैपग्रिड बच्चों का आकार मापने

इसके कारण, निम्नलिखित XAML तीसरे आइटम को क्लिप करेगा।

<VariableSizedWrapGrid Orientation="Horizontal"> 
     <Rectangle Width="50" Height="100" Margin="5" Fill="Blue" /> 
     <Rectangle Width="50" Height="50" Margin="5" Fill="Red" /> 
     <Rectangle Width="50" Height="150" Margin="5" Fill="Green" /> 
     <Rectangle Width="50" Height="50" Margin="5" Fill="Red" /> 
     <Rectangle Width="50" Height="100" Margin="5" Fill="Red" /> 
    </VariableSizedWrapGrid> 

VariableSizedWrapGrid उपायों पहला आइटम और उसके बाद बाकी बच्चों पहले एक के वांछित आकार के साथ मापा जाता है की तरह लगता है।

कोई कामकाज?

उत्तर

3

आप प्रत्येक आयत VariableSizeWrapGrid.ColumnSpan और VariableSizeWrapGrid.RowSpan पर संलग्न गुण का उपयोग करने के साथ-साथ VariableSizeWrapGrid के लिए एक ItemHeight और ItemWidth जोड़ने की जरूरत है:

<VariableSizedWrapGrid Orientation="Horizontal" ItemHeight="50" ItemWidth="50"> 
    <Rectangle 
     VariableSizedWrapGrid.ColumnSpan="1" 
     VariableSizedWrapGrid.RowSpan="2" 
     Width="50" Height="100" Margin="5" Fill="Blue" /> 
</VariableSizedWrapGrid> 
0

इसकी हो सकता है सबसे अच्छा नहीं जिस तरह से है, लेकिन यह है कैसे मैं अपने @MetroRSSReader अनुप्रयोग में यह किया है

<common:VariableGridView.ItemsPanel> 
       <ItemsPanelTemplate> 
        <VariableSizedWrapGrid ItemWidth="225" 
              ItemHeight="{Binding ElementName=bounds, Path=Text}" 
              MaximumRowsOrColumns="5" Orientation="Vertical" 
              /> 
       </ItemsPanelTemplate> 
       </common:VariableGridView.ItemsPanel> 
     </common:VariableGridView> 

सूचना ItemHeight मूल्य एक TextBlock

के लिए बाध्य है

कौन सा LayoutAwarePage.cs में सेट है

public string Fix_item_height_for_current_screen_resolution() 
    { 
     var screenheight = CoreWindow.GetForCurrentThread().Bounds.Height; 
     var itemHeight = screenheight < 1000 ? "100" : "140"; 

     return itemHeight; 
    } 

आप एक VariableSizeWrapGrid उपयोग करने के लिए आप अपने खुद के GridView कस्टम नियंत्रण बना सकते हैं और PrepareContainerForItemOverride ओवरराइड और तत्वों स्थापित करना चाहिए पूर्ण स्रोत कोड http://metrorssreader.codeplex.com/SourceControl/changeset/view/18233#265970

0

ब्राउज़ कर सकते हैं उस विधि के अंदर रोशन और कॉलमस्पैन। इस तरह प्रत्येक तत्व की अपनी ऊंचाई/चौड़ाई होगी।

यहाँ एक अच्छा ट्यूटोरियल है/जेरी निक्सन ने के माध्यम से चलना: http://dotnet.dzone.com/articles/windows-8-beauty-tip-using

+1

किसी भी विचार मॉडल में बदलाव होने पर कोई भी पंक्ति/कॉल स्पैन जोड़ सकता है और अद्यतन हो सकता है। PrepareContainerForItemOverride परिवर्तनों पर नहीं कहा जाता है। –

0

आज यह एक यह पता लगाने की प्रबंधित। WinRT XAML Toolkit (http://winrtxamltoolkit.codeplex.com) में आपको VisualTreeHelperExtension.cs का उपयोग करने की आवश्यकता होगी। मेरे लिए मैं एक सूची दृश्य को समायोजित करने की कोशिश कर रहा था जिसमें ग्रिड व्यू को इसके आइटमपैनेल टेम्पलेट के रूप में रखा गया था, वही अवधारणा आपके लिए लागू होनी चाहिए।

1) अपने ListView की LayoutUpdated घटना के लिए संलग्न (यह तब होता है जब आप आकार अद्यतन करने के लिए)

_myList.LayoutUpdated += _myList_LayoutUpdated;

2) का प्रयोग करें VisualTreeHelperExtensions.GetDescendantsOfType() से ढूंढना चाहेंगे आपके आइटम के डेटा टेम्पलेट में एक सामान्य (और अद्वितीय) तत्व प्रकार (उदा: एक टेक्स्टब्लॉक जो चौड़ाई में गतिशील है):

var items = VisualTreeHelperExtensions.GetDescendantsOfType<TextBlock>(_myList); 

if (items == null || items.Count() == 0) 
    return; 

3) पाया मदों की अधिकतम चौड़ाई प्राप्त करें:

double maxWidth = items.Max(i => i.ActualWidth) + 8;

4) VisualTreeHelperExtensions का प्रयोग करें।GetDescendantsOfType() अपने ListView के लिए मुख्य WrapGrid कंटेनर को खोजने के लिए:

var wg = _categoryList.GetDescendantsOfType<WrapGrid>(); 
if (wg == null || wg.Count() != 1) 
    throw new InvalidOperationException("Couldn't find main ListView container"); 

5) maxWidth को WrapGrid के ItemWidth सेट आप गणना:

wg.First().ItemWidth = maxWidth;

संबंधित मुद्दे