user3683028
user3683028

Reputation: 3

Dynamic Listview Layout in Windows Phone App 8.1

I am new to Windows Phone App Development. I am showing list of some items in listview. It's working perfect for me but when the issue is with design. how can i set dynamic width of my listview. i.e. if i open my app in different resolution & mode, it should be in full width.

If i give fix width to my listview, it is not showing properly in all resolutions & mode. i am aware with * sizing but when i give * sizing, it is giving me error in App.g.i.cs file. On this statement

if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();

Please advise.

Upvotes: 0

Views: 626

Answers (1)

Jogy
Jogy

Reputation: 2475

To make the items of a ListView take the full available width, set the item container style as follows:

<ListView.ItemContainerStyle>
  <Style TargetType="ListViewItem">
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
  </Style>
</ListView.ItemContainerStyle>

To layout list view items like you wanted in the comment, you can use a Grid:

<ListView.ItemTemplate>
  <DataTemplate>
    <Grid HorizontalAlignment="Stretch" >
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="20" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="20" />
      </Grid.ColumnDefinitions>
      ... put your controls in the appropriate grid cells
    </Grid>
  </DataTemplate>
</ListView.ItemTemplate>

Upvotes: 2

Related Questions