开发者

How to display data which is of different width in single ListBox in silverlight?

开发者 https://www.devze.com 2023-02-16 04:31 出处:网络
I am developing window phone 7 application. I am new to the window phone 7 application. I am binding the data dynamically to the TextBlock inside the ListBox. I am using the following code to display

I am developing window phone 7 application. I am new to the window phone 7 application. I am binding the data dynamically to the TextBlock inside the ListBox. I am using the following code to display the data in the ListBox.

<ListBox Margin="16,161,30,186" Name="IncomeSummaryListBox" DataContext="{Binding}" Grid.ColumnSpan="3">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock TextWrapping="Wrap" Width="200" Text="{Binding Key}" Foreground="Gray"></Te开发者_运维技巧xtBlock>
                                    <TextBlock TextWrapping="Wrap" Width="200" Text="{Binding Value}" Foreground="Orange"></TextBlock>
                                    <Line X1="-3400" Y1="32" X2="10" Y2="32" Stroke="Gray" StrokeThickness="1"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                        <ListBox.Template>
                            <ControlTemplate>
                                <ScrollViewer HorizontalScrollBarVisibility="Visible">
                                    <ItemsPresenter />
                                </ScrollViewer>
                            </ControlTemplate>
                        </ListBox.Template>
                    </ListBox>

I am using the combobox to display the data in the list box. The data in the listbox changes based on the selection in the combobox. So for some selection I want the width of the textblock as 1400 and for some selection I want the width for the textblock as 200. This is the requirement for the Text="{Binding Key}" textblock. Without specifying the correct width as described above the data can not be displayed properly. How to resolve the above issue. Can you please provide me any code or link through which I can resolve the above issue ? If I am doing anything wrong then please guide me.


Why don't you create a binding for the Width attribute as well? Then you can set it to either 1400 or 200 as required within the page class.

0

精彩评论

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

关注公众号