2014-01-22 28 views
0

我想從Windows手機工具包使用LoopingSelector。 選擇器本身工作正常,但我在單個項目ItemSize上有問題。LoopingSelectorItem的單個ItemSize

我沒有與其他尺寸相同的單個項目,所以我想讓每一個項目都只在屏幕上佔用必要的空間。

但我一直無法得到這種行爲。任何人有任何反饋?我在底部附加了代碼。我必須在這裏錯過顯而易見的事

<Style TargetType="toolkitPrimitives:LoopingSelectorItem"> 
     <Setter Property="Foreground" Value="{StaticResource PhoneSubtleBrush}"/> 
     <Setter Property="Padding" Value="6"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate> 
        <Border x:Name="root" CacheMode="BitmapCache" Background="Transparent" Padding="{TemplateBinding Padding}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 

         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 

           <VisualStateGroup.Transitions> 
            <VisualTransition From="Normal" To="Expanded" GeneratedDuration="0:0:0.33" /> 
            <VisualTransition From="Expanded" To="Normal" GeneratedDuration="0:0:0.33" /> 
           </VisualStateGroup.Transitions> 

           <VisualState x:Name="Normal" /> 

           <VisualState x:Name="Expanded"> 
            <Storyboard> 
             <DoubleAnimation Storyboard.TargetName="border" Storyboard.TargetProperty="Opacity" To="0.8" Duration="0"/> 
            </Storyboard> 
           </VisualState> 

           <VisualState x:Name="Selected"> 
            <Storyboard> 
             <DoubleAnimation Storyboard.TargetName="Text" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/> 
             <DoubleAnimation Storyboard.TargetName="border" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="border" Storyboard.TargetProperty="BorderBrush" Duration="0"> 
              <ObjectAnimationUsingKeyFrames.KeyFrames> 
               <DiscreteObjectKeyFrame KeyTime="0" Value="DarkGray" /> 
              </ObjectAnimationUsingKeyFrames.KeyFrames> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="contentControl" Storyboard.TargetProperty="Foreground" Duration="0"> 
              <ObjectAnimationUsingKeyFrames.KeyFrames> 
               <DiscreteObjectKeyFrame KeyTime="0" Value="White" /> 
              </ObjectAnimationUsingKeyFrames.KeyFrames> 
             </ObjectAnimationUsingKeyFrames> 

             <ObjectAnimationUsingKeyFrames Storyboard.TargetName="contentControl" Storyboard.TargetProperty="FontWeight" Duration="0"> 
              <ObjectAnimationUsingKeyFrames.KeyFrames> 
               <DiscreteObjectKeyFrame KeyTime="0" Value="Bold" /> 
              </ObjectAnimationUsingKeyFrames.KeyFrames> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 

          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 

         <Border.RenderTransform> 
          <TranslateTransform x:Name="Transform"/> 
         </Border.RenderTransform> 

         <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
          <Rectangle x:Name="background" Margin="0" Opacity="0" Fill="{StaticResource PhoneAccentBrush}" CacheMode="BitmapCache"/> 

          <Border x:Name="border" Opacity="0" BorderThickness="0" BorderBrush="{StaticResource PhoneSubtleBrush}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> 
           <ContentControl x:Name="contentControl" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch"> 
            <TextBlock x:Name="Text" TextWrapping="Wrap" Opacity="0.7" Text="{Binding Text}" Foreground="{StaticResource PhoneForegroundBrush}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" /> 
           </ContentControl> 
          </Border> 
         </Grid> 

        </Border> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

    <toolkitPrimitives:LoopingSelector x:Name="LoopingSelector" ItemMargin="10" ItemSize="430,120" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 

回答

1

我看到幾個VerticalAlignment值設置爲「stretch」。這將垂直拉伸元素,直到填充其父元素。嘗試將這些元素的高度屬性設置爲「自動」。 VerticalAlignment值應該被刪除或設置爲「伸展」。寬度和水平對齊也一樣。

<Border.RenderTransform> 
    <TranslateTransform x:Name="Transform"/> 
</Border.RenderTransform> 
<Grid HorizontalAlignment="Stretch" Height="auto"> 
    <Rectangle x:Name="background" Margin="0" Opacity="0" Fill="{StaticResource PhoneAccentBrush}" CacheMode="BitmapCache"/> 
    <Border x:Name="border" Opacity="0" BorderThickness="0" BorderBrush="{StaticResource PhoneSubtleBrush}" Height="auto" HorizontalAlignment="Stretch"> 
     <ContentControl x:Name="contentControl" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Height="auto" VerticalContentAlignment="Stretch"> 
      <TextBlock x:Name="Text" TextWrapping="Wrap" Opacity="0.7" Text="{Binding Text}" Foreground="{StaticResource PhoneForegroundBrush}" Height="auto" HorizontalAlignment="Stretch" /> 
     </ContentControl> 
    </Border> 
</Grid> 
+0

好的,謝謝,今天下班回家時我會試試這個。 –

+0

今天意識到我在迴應中犯了一個錯誤。 Height值應該設置爲「auto」,VerticalAlignment值應該設置爲除「stretch」(或刪除)之外的任何值。 – philorube

+0

Unfortionaly它不起作用。由於您將項目大小放在LoopingSelector上,所有項目都會獲得該大小:( –

相關問題