开发者

Adding a label in front of my textblock

开发者 https://www.devze.com 2023-03-01 17:50 出处:网络
I have a list which gets data from a web service but the data needs a label or another textblock to say what that data is. Is there a way of inserting this within this listbox?

I have a list which gets data from a web service but the data needs a label or another textblock to say what that data is. Is there a way of inserting this within this listbox?

so my desired outcome would be

"HIN Number:" - then display the textblock which is bound to HINNumber

"Category Letter:" - then display the textblock which is bound to categoryLetter

"Category 1:" - then display the textblockwhich is bound to category1

"Category 2:" - then display the textblockwhich is bound to category2

"Category 3:" - then display the textblockwhich is bound to category3

I thought I could just align another textblock up next to the matching databound textblock but some values are null and so the position of the listbox is constantly changing so this wouldnt work.

        <ListBox x:Name="HINList" Margin="0,300,-12,0" ItemsSource="{Binding Details}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Margin="0,0,0,17" Width="432">
                        <TextBlock Text="{Binding HINNumber}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                        <TextBlock Text="{Binding CategoryLetter}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
                        <T开发者_如何学编程extBlock Text="{Binding Category1}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
                        <TextBlock Text="{Binding Category2}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
                        <TextBlock Text="{Binding Category3}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>


It depends if you want the label to the left of or above each textblock.

Above is easier - just use extra textblocks in the stackpanel:

<StackPanel Margin="0,0,0,17" Width="432">
    <TextBlock Text="HIN Number" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
    <TextBlock Text="{Binding HINNumber}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
    <TextBlock Text="Category Letter" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
    <TextBlock Text="{Binding CategoryLetter}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
    <TextBlock Text="Category 1" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
    <TextBlock Text="{Binding Category1}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
    <TextBlock Text="Category 2" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
    <TextBlock Text="{Binding Category2}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>

    <StackPanel Visibility={Binding Category3Visibility}>
        <TextBlock Text="Category 3" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
        <TextBlock Text="{Binding Category3}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextNormalStyle}"/>
    </StackPanel>       

</StackPanel>


    public System.Windows.Visibility Category3Visibility
    {
        get { return string.IsNullOrEmpty(Category3) ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible; }
    }

If you want the labels to the right, use a 2 column grid to layout the controls.

0

精彩评论

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