How would I go about setting the width of the list view to be the same as the width of the expander that it is inside?
<Expander x:Name="expander"
IsExpanded="False"
ExpandDirection="Down"
Header="Main"
HorizontalAlignment="Stretch"
Grid.Column="1"
Grid.Row="1">
<Expander.Content>
<ListView x:Name="listView"
SelectionMode="None"
IsItemClickEnabled="True"
HorizontalAlignment="Stretch"
ItemClick="ListItemClicked"
ItemTemplate="{StaticResource ListViewTemplate}"/>
</Expander.Content>
</Expander>
Add HorizontalContentAligment="Stretch" to the Expander like this.
<Expander
x:Name="expander"
Grid.Row="1"
Grid.Column="1"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
ExpandDirection="Down"
Header="Main"
IsExpanded="False">
<Expander.Content>
<ListView
x:Name="listView"
HorizontalAlignment="Stretch"
IsItemClickEnabled="True"
SelectionMode="None" >
<ListViewItem Content="Test"/>
</ListView>
</Expander.Content>
</Expander>
Related
I am trying to have the content of gridview cell to stretch the height so there is no scrolling within the cell.
Here's my code:
<Grid Grid.Row="1" Padding="50 10 50 10">
<ListView IsTapEnabled="False"
Background="White"
SizeChanged="categoryListView_SizeChanged"
x:Name="categoryListView"
Height="auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ItemsSource="{Binding Source={StaticResource stores}, Path=CollectionGroups}"
ItemTemplate="{StaticResource CategoriesList}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</Grid>
and here is my data template:
<DataTemplate x:Key="CategoriesList">
<Grid x:Name="AlphabetGrid" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0 0 20 0">
<TextBlock x:Name="CategoryName" FontSize="24" Text='{Binding Group.Key}' Foreground="#412141" FontWeight="Bold" HorizontalAlignment="Left" TextAlignment="Left"/>
<Grid Margin="0 30 0 0">
<ListView ItemsSource="{Binding Group.Items}" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Margin="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="4*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" x:Name="unit_number" FontSize="15" Text='{Binding unit}' Foreground="red" HorizontalAlignment="Left" TextAlignment="Left"/>
<TextBlock Grid.Column="1" x:Name="name" FontSize="15" Text='{Binding name}' Foreground="red" HorizontalAlignment="Left" TextAlignment="Left"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Grid>
</DataTemplate>
How can I achieve this? Any recommendations?
This is how it looks right now.
I can reproduce your issue: it seems that ItemsWrapGrid uses some strange logic when row heights are calculated automatically. You can set its ItemHeight property manually to avoid this problem, but this solution is far from being elegant.
Alternatively you can use the WrapPanel XAML Control from the UWP Community Toolkit as an ItemsPanelTemplate for your ListView to make the items stretch their height to fit the content
<ListView>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controls:WrapPanel/>
<ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ListView>
however, your grid is going to have a lot of empty space then
If that's not what you want, you can eliminate most of the empty spaces by changing the orientation of the WrapPanel from horizontal to vertical
and even further by not grouping your items into separate controls by category
how is it possible to add a button or another visual style element to only one hubsection of the default hubpage template in Windows Phone 8.1?
I would like to add a refresh button above my ListView.
<Hub x:Name="Hub" x:Uid="Hub" Header="BuLi Tweet" Foreground="White" Background="{StaticResource RasenHintergrund}">
<HubSection x:Uid="HubSection1" Header="Aktueller Spieltag" Width="400"
DataContext="{Binding Groups[0]}" HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}">
<DataTemplate>
<ListView
ContinuumNavigationTransitionInfo.ExitElementContainer="True">
<GridView
Margin="5,0,0,0"
ItemsSource="{Binding Items}"
AutomationProperties.AutomationId="ItemGridView"
AutomationProperties.Name="Items In Group"
ItemTemplate="{StaticResource MatchIcon}"
SelectionMode="None"
IsItemClickEnabled="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollMode="Enabled"
ItemClick="ItemView_ItemClick"
ContinuumNavigationTransitionInfo.ExitElementContainer="True">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
</ListView>
</DataTemplate>
</HubSection>
I hope you want button inside first hub section before listview. Just add grid and define RowDefinations for Grid
<HubSection x:Uid="HubSection1" Header="Aktueller Spieltag" Width="400"
DataContext="{Binding Groups[0]}" HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}">
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Content="Refresh" Visibility="{Binding}"/>
<ListView Grid.Row="1"
ContinuumNavigationTransitionInfo.ExitElementContainer="True">
<GridView
Margin="5,0,0,0"
ItemsSource="{Binding Items}"
AutomationProperties.AutomationId="ItemGridView"
AutomationProperties.Name="Items In Group"
ItemTemplate="{StaticResource MatchIcon}"
SelectionMode="None"
IsItemClickEnabled="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollMode="Enabled"
ItemClick="ItemView_ItemClick"
ContinuumNavigationTransitionInfo.ExitElementContainer="True">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
</ListView>
</Grid>
</DataTemplate>
</HubSection>
<GridView
Grid.Row="1"
AutomationProperties.AutomationId="ItemGridView"
AutomationProperties.Name="Grouped Items"
ItemsSource="{Binding ServiceOrderList}"
ItemTemplate="{StaticResource ServiceOrderListItemTemplate}"
SelectedItem="{Binding SelectedServiceOrder, Mode=TwoWay}"
IsSwipeEnabled="false">
<winRtBehaviors:Interaction.Behaviors>
<behaviors:EventToBoundCommandBehavior
Command="{Binding ServiceOrderItemClickCommand}"
Event="Tapped" />
</winRtBehaviors:Interaction.Behaviors>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Vertical" MaximumRowsOrColumns="3" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
I want use to be able to do a left click on the items of gridview but dosn't want to allow them to right click and select an item, please help.
If you don't want the items to be selectable at all, set SelectionMode="None" and IsItemClickEnabled="True" along with setting an ItemClick event.
If you want them to be selectable, but only left click, you can set IsRightClickEnabled="False".
Another way is put RightTapped event in your GridView.ItemTemplate which is implement : e.Handled = true
<GridView>
<GridView.ItemTemplate>
<DataTemplate>
<Grid Margin="30,10"
Width="350" Tapped="Grid_Tapped_1" RightTapped="Grid_RightTapped">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Image Height="40" Source="{Binding Path=Image}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,-3,11,0"/>
<TextBlock FontSize="24" FontWeight="SemiBold" FontFamily="Segoe WP" Foreground="#232323" Text="{Binding Path=RoomTypeString}" VerticalAlignment="Center"/>
</StackPanel>
<TextBlock FontSize="24" Text="{Binding Path=RoomCountString}"
Foreground="#232323" FontFamily="Segoe WP"
TextTrimming="CharacterEllipsis"/>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
In a user control, I put a listbox which is bound to a dynamic datasource. This usercontrol will be in a popup window. I want to this list box can fill the rest of space of the window. Here is the Xaml I tried:
<ComboBox x:Name="cmbx1" Grid.Column="0" Grid.Row ="0" Margin="5"
Width="150" VerticalAlignment="Center" HorizontalAlignment="Left" SelectionChanged="filters_SelectionChanged">
......
</ComboBox>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Column="1" Grid.Row="0">
<Button Content="Test" Margin="5" Click="Button_Add" />
</StackPanel>
<DataGrid x:Name="ListGrid" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
......
</DataGrid>
<ComboBox x:Name="cmb2" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="5">
......
</ComboBox>
<ListBox x:Name="lstSharing" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,10,0"
Width="{Binding Width, ElementName=ListGrid}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<tkit:WrapPanel Orientation="Horizontal" MaxWidth="650" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="3" Width="Auto">
<CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" />
<TextBlock Text="{Binding ItemName}" Width="120" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
What I want it height and width of list box can be setup dynamically based on windows size, the items bound to list box. But it is not working properly. Initially, the listbox has no scrollbar, I need to resize window manually so that scrollbar on display. I can not dynamically to change with, so I put MaxWidth =600. Otherwise, it always display all item in one row.
How to resolve this problem?
This is untested, but I would try something like this:
<ListBox x:Name="lstSharing"
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="0,0,10,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<tkit:WrapPanel Orientation="Horizontal"
MaxWidth="{Binding ElementName=lstSharing, Path=ActualWidth}" />
</ItemsPanelTemplate>
It's a little difficult to know whether this will work without seeing the parent containers, but it should point you in the right direction.
I'm trying to horizontal strech button inside ListView, but my xaaml code doesn't work:
<ListView Grid.Row="2" ItemsSource="{Binding Path=Items}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
<ListView.ItemTemplate>
<DataTemplate>
<Button Grid.Row="2" Background="White" BorderThickness="4,0,0,1" BorderBrush="#8c0095" Margin="32,-3,32,17" Padding="0" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<TextBlock Text="{Binding Name}" Foreground="#8c0095" FontSize="20" Margin="15,1,0,10" FontWeight="Medium" />
</Button>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
How can I solve this?