locked
Xaml for a listview with 2 columns, one left align one right align, full width RRS feed

  • Question

  • I have tried about every thing to get a listview where there are 2 textboxes per line. First text box left align second one right align, and stretching the full width of the screen. Can anyone please help me?
    Thursday, May 14, 2015 8:48 PM

Answers

  • Hi Rudolf,

    >>First text box left align second one right align, and stretching the full width of the screen.

    For aligning the textbox right/left/stretch, we can set the HorizontalAlignment property. For leting it fully fill the screen, we can bind the ListView's Width to the MainGrid's Width and I have created the following xaml, please try to check it:

       <Grid Name="MainGrid">
            <ListView Name="allDevicesListView" Width="{Binding ElementName=MainGrid,Path=ActualWidth}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Width="{Binding ElementName=allDevicesListView,Path=Width}" Orientation="Horizontal">
                            <Grid Width="{Binding ElementName=allDevicesListView,Path=Width}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="2*"/>
                                </Grid.ColumnDefinitions>
                                <TextBox Text="{Binding name}" Grid.Column="0" HorizontalAlignment="Left"/>
                                <TextBox Text="{Binding id}" Grid.Column="1" HorizontalAlignment="Right"></TextBox>
                            </Grid>
                        </StackPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
                <ListView.ItemContainerStyle>
                    <Style TargetType="ListViewItem">
                        <Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
                    </Style>
                </ListView.ItemContainerStyle>
            </ListView>
        </Grid>

    If I have misunderstood you, please feel free to let me know.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.





    Friday, May 15, 2015 8:31 AM