Silverlight: last item in ItemsControl

I have an ItemControl. For the last item in the ItemsControl, I want to hide the TextBox containing the comma. Is there any way to do this using XAML?

        <ItemsControl>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Visibility="{Binding Value, Converter={StaticResource NotEmpty}}">
                        <TextBlock Text="{Binding QuestionName}" />
                        <TextBlock Text=" " />
                        <TextBlock Text="{Binding Answer}"/>
                        <TextBlock Text=", " />
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>

            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <toolkit:WrapPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
+3
source share
2 answers

What about

<TextBlock Text=", " Visibility="{Binding LastItemVisibility}" />

something looks like in your model

public Visibility LastItemVisibility
{
    get { return MyCollection.LastOrDefault() == this ? Visibility.Collapsed : Visibility.Visible; }
}

?

+4
source

It is annoying that it is not easy to solve with a converter. In fact, if you could bind to ConverterParameter (which is not possible in Silverlight v4), you could achieve what you want quite easily.

, , , ControlControl, , bounditem itemssource. , . ItemsControl

  <local:ItemsControlVisibilityHelper ShowIfLast="False" ShowIfFirst="True"  ShowIfNotLastOrFirst="True"
                                                                    ItemsControl="{Binding ElementName=x_ItemsControl}"
                                                                    BoundItem="{Binding}"
                                                                    >
                                    <TextBlock Text=", "></TextBlock>
                                </local:ItemsControlVisibilityHelper>
+1

Source: https://habr.com/ru/post/1782519/


All Articles