开发者

Itemscontrol stretch silverlight

开发者 https://www.devze.com 2023-03-25 14:41 出处:网络
Inside my itemsControl the item are not occupying the whole width of the user control. Am using DataTemplateSelector (manually written class) for selecting the type of template.

Inside my itemsControl the item are not occupying the whole width of the user control. Am using DataTemplateSelector (manually written class) for selecting the type of template.

I checked the post Silverlight: Set Items Widths in ItemsControl to Stretch but its not working for me. Items are not automatically stretching and utilizing the full space. Please help! Thanks in advance

<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>


Items inside your datatemplate will always take up all available width due to the star width. The problem is most likely with the itemscontrol itself. Are you sure that the itemscontrol is not contained in a StackPanel, or auto-width Grid column. Is the HorizontalAlignment of the ItemsControl set to Left ?

0

精彩评论

暂无评论...
验证码 换一张
取 消