locked
Getting ItemControl to list TextBlock horizontally

    General discussion

  • I am working on a new feature in a Silverlight app. It needs to display a list of things (prices) horizontally. So I created a ItemControl, changed it's ItemsPanel to a StackPanel, then went off an created a template, ProductPrice, to display each of the prices. Everything works, except it only shows the first price in the ObservableCollection.

    I do know that the ProductPrice Control Template is being used because when the converter is removed, the price is no longer formatted.

    I am 99.9% sure there is something wrong with the XAML code, any thoughts?

    	<sdk:ChildWindow.Resources>
    
    		<converters:BooleanVisibilityConverter x:Key="BooleanVisibilityConverter"/>
    		<converters:NumericCurrencyConverter x:Key="NumericCurrencyConverter"/>
    
            <ControlTemplate x:Key="ProductPrice" TargetType="ItemsControl">
    			<TextBlock Margin="0,1,0,0"
            		Style="{StaticResource ProductPriceTextBlockStyle}"  
    				Text="{Binding Price, Converter={StaticResource NumericCurrencyConverter}, Mode=OneWay}"/>
    		</ControlTemplate>
            
    		<DataTemplate x:Key="ProductItemTemplate">
    			<Grid Margin="3,6,3,12" d:DesignWidth="500" d:DesignHeight="120">
    				<Grid.RowDefinitions>
    					<RowDefinition Height="Auto" />
    					<RowDefinition Height="*" />
    				</Grid.RowDefinitions>
    				<Grid.ColumnDefinitions>
    					<ColumnDefinition Width="250"/>
    					<ColumnDefinition Width="*"/>
    					<ColumnDefinition Width="104"/>
    				</Grid.ColumnDefinitions>
    				<TextBlock Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" 
            			Style="{StaticResource ProductNameTextBlockStyle}" Margin="0,1,0,0" 
    					Text="{Binding ItemName, Mode=OneWay}" />
    				<TextBlock TextWrapping="Wrap" Margin="0,3,6,0" Grid.Row="1" 
    					Text="{Binding Description, Mode=OneWay}" Grid.ColumnSpan="2"/>
    
    				<ItemsControl Grid.Column="1" HorizontalAlignment="Right" Margin="0,1,0,0" Grid.ColumnSpan="2" 
    					ItemsSource="{Binding Prices}" 
    					Template="{StaticResource ProductPrice}">
    					<ItemsControl.ItemsPanel>
    						<ItemsPanelTemplate>
    							<StackPanel Orientation="Horizontal"/>
    						</ItemsPanelTemplate>
    					</ItemsControl.ItemsPanel>	
    				</ItemsControl>
    					
    				<inputToolkit:NumericUpDown 
                        Height="30" VerticalAlignment="Top" Margin="0,3,0,0" FontSize="14.667" Grid.Column="2" Grid.Row="1" Minimum="0"
                        Style="{StaticResource NumericUpDownLeftRightStyle}" 
                        Value="{Binding Qty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
    					IsEnabled="{Binding ElementName=LayoutRoot, Path=DataContext.IsProductsEnabled}"
                        />
    			</Grid>
    		</DataTemplate>
    	</sdk:ChildWindow.Resources>
    

    Sunday, July 16, 2017 11:32 AM

All replies


  • Hi EHCarleton,

    From your description and code snippet, we cannot restore your phenomenon.

    So, I suggest you can include all necessary code snippets/necessary message/screenshots for anyone else to be able to reproduce your issue from scratch along with a detailed description about the results including any exception messages or you can upload your demo to OneDrive(Including your test material). We can download it and debugging. This will help us quickly analyze your problem.
    Share OneDrive files and folders:
    https://support.office.com/en-us/article/Share-OneDrive-files-and-folders-9fcc2f7d-de0c-4cec-93b0-a82024800c07


    Best Regards,

    Yohann Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 17, 2017 6:51 AM
  • To be totally honest, I didn't expect anyone to use my code sample to reproduce anything.  I was simply hoping someone who knew Silverlight XAML programming pretty well could have a look at my XAML and see if there is anything obviously missing.  I guess this is not the right place to find such folks, I will go Google things and see what I can find.
    Tuesday, July 18, 2017 12:03 AM

  • Hi EHCarleton,

    From your further description, I will change this question to discuss posts, so that we can discuss together.

    The following  style for your reference.

       <ItemsControl
                    x:Name="SeaList"                
                    ItemsSource="{Binding Titles}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
    
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding FirstName}"/>
                                <TextBlock Text=" "/>
                                <TextBlock Text="{Binding LastName}"/>
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>


    Best Regards,

    Yohann Lu



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 18, 2017 2:41 AM