2011-08-01 11 views
0

私のitemsControlの中にアイテムはユーザーコントロールの幅全体を占めていません。テンプレートの種類を選択するためにDataTemplateSelector(手書きクラス)を使用しています。Itemscontrol stretch silverlight

私は投稿Silverlight: Set Items Widths in ItemsControl to Stretchをチェックしましたが、私のために働いていません。アイテムは自動的に伸びず、フルスペースを利用しません。助けてください!事前に感謝します

<ItemsControl ItemsSource ="{Binding}" Margin="0,5,0,0" HorizontalContentAlignment="Stretch" > 
    <ItemsControl.ItemTemplate> 
     <DataTemplate>      
      <local:AddressFieldsTemplateSelector Content="{Binding}" x:Name="addressTemplateSelectorObject"> 
       <!-- TextBox template--> 
       <local:AddressFieldsTemplateSelector.TextBoxDataTemplate> 
        <DataTemplate>         
         <Grid Margin="0,0,0,5" HorizontalAlignment="Stretch" > 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="0.5*" /> 
           <ColumnDefinition Width=".1*" /> 
            <ColumnDefinition Width="*"/> 

          </Grid.ColumnDefinitions> 
          <TextBlock Text="{Binding AddressFieldName}" Grid.Column="0" Style="{StaticResource DefaultTheme_TextBlockStyle}"/> 
          <TextBox Text="{Binding AddressFieldValue, Mode=TwoWay}" Grid.Column="2" Style="{StaticResource TextBoxStyle}" TextWrapping="NoWrap" MaxLength="50" HorizontalAlignment="Stretch" /> 
         </Grid> 
        </DataTemplate> 
       </local:AddressFieldsTemplateSelector.TextBoxDataTemplate> 
      </local:AddressFieldsTemplateSelector> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 
+0

問題の画像が表示されますので、問題が発生していることを確認できますか?返信いただきありがとうございます。 – StephenT

答えて

0

あなたのdatatemplate内の項目は、常にスター幅のために利用可能なすべての幅を占有します。この問題はitemscontrol自体の可能性が最も高いです。 itemscontrolがStackPanel、または自動幅がGridの列に含まれていないことを確認してください。 ItemsControlのHorizontalAlignmentLeftに設定されていますか?

+0

はいItemsControlはグリッド内に配置されます。そのグリッドはスタックパネルの内側に配置されています。私はItemsControlのHorizo​​ntalALignmentプロパティを設定しなかったので、デフォルト値を取る必要があります。それがどのようにアイテムストレッチプロパティに影響を与えるかわからない? – Sai

+0

あなたのグリッドは幅を持っていますか?あなたのStackPanelの向きは? – Danexxtone

関連する問題