E
E
eopen2016-05-01 11:46:10
C++ / C#
eopen, 2016-05-01 11:46:10

How to style DataTemplate for ListBox?

<ListBox
            x:Name="audioView" 
            Width="380" Grid.Row="1" 
            Grid.ColumnSpan="3" 
            VerticalAlignment="Stretch" 
            HorizontalAlignment="Stretch" 
            SelectionMode="Extended"
            >
<ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock FontWeight="Bold" Text="{Binding artist}" Tag="{Binding url}"  Tapped="TextBlock_Tapped"/>
                        <TextBlock Text=" – " />
                        <TextBlock Text="{Binding title}" Tag="{Binding url}"  Tapped="TextBlock_Tapped"  />
                            
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

There is XAML code, ListBox elements are displayed according to the template. It should look something like Artist - Name, but it turns out Artist - Name .
Where do the spaces on the sides of the hyphen go?
If you put it like this: (without a hyphen) It turns out together at all. How to fix?
<TextBlock Text=" " />

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2016-05-01
@eopen

1st option: Use Margin and Padding to achieve the desired effect.
2nd option: use xml:space="preserve" in the TextBlock where spaces need to be preserved.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question