I have a data bound ListView that uses a rather strange heights for every ListViewItem after I start using an ItemTemplate.
<ListView ItemsSource="{Binding Path=AllTvShows}">
<ListView.ItemTemplate>
<DataTemplate>
<Label FontStretch="Normal" VerticalAlignment="Center" Content="{Binding Path=Name}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
This is how it looks like:
Without the ItemTemplate the labels have the normal height (more adjacent). How should I specify the Label so that it would render normal?
Use a TextBlock instead of a Label:
<ListView ItemsSource="{Binding Path=AllTvShows}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Related
I have such a list view
And there is a .xalm
...
<ListView
x:Name="LVLog"
ToolTip="Log of task(s) execution"
Background="WhiteSmoke"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"/>
...
And there is how I add items in LVLog
LVLog.Items.Add(message.Log);
As you can see if line a long enough it goes out of the borders and user need to scroll horizontaly in order to read log up to the end.
Question is: is there is a way to write line at the next line if it came to the borders?
You could use a TextBlock as an ItemTemplate and set TextTrimming on it. So the text will be trimmed
Long long lo..
and the full text you will see in tooltip:
<ListView ItemsSource="{Binding YourCollection}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ...}" TextTrimming="CharacterEllipsis" ToolTip="{Binding ...}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
If you want to have more lines, then just set TextWrapping="Wrap" in the TextBlock:
<ListView ItemsSource="{Binding YourCollection}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ...}" TextWrapping="Wrap"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I have a ViewModel with about 200 contacts and I am binding it to a ListView
<Grid>
<ScrollViewer
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
<ListView x:Name="ContactListing" ItemsSource="{Binding ContactListing}" >
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=DisplayName}" />
<Image Source="{Binding Thumbnail,Converter={StaticResource ResourceKey=contactConv}}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollViewer>
</Grid>
Would be great if someone could explain the details behind the ScrollViewers visibility
A ListView control already contains a ScrollViewer and implements scrolling based on the amount of items, there is no need to wrap this control in another ScrollViewer. You can double check this in the default ControlTemplate of ListView at line 6219 in the generic.xaml file containing all Windows 10 styles:
C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.10240.0\Generic\generic.xaml
So you simply have to remove the ScrollViewer from your XAML fragment.
<Grid>
<ListView x:Name="ContactListing" ItemsSource="{Binding ContactListing}" >
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=DisplayName}" />
<Image Source="{Binding Thumbnail,Converter={StaticResource ResourceKey=contactConv}}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
Note: As you're using a ListView, I suppose you want all your items stacked above each other. If you want multiple columns to show your items, use a GridView instead.
I have a news model which has Title and Excerpt properties and need to display them like this image.
ObservableCollection<NewsModel>(getNews())
my question is what control should I use to accomplish this view?
You could use ListView to accomplish your task, Something like this,
<ListView Name="listView1" ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock Text="{Binding Path=Title}" MinWidth="80" />
<TextBlock Text="{Binding Path=Description}" MinWidth="80" />
</WrapPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
I'm trying to bind my stackpanel's visibility to the checkbox's isChecked value. It's a common problem, but I just can't figure it out.
Converter:
<Page.Resources>
<common:BooleanToVisibilityConverter x:Key="BoolToVis"/>
</Page.Resources>
StackPanel I want to mess with(I removed some code, so don't you worry about listview's binding, I set it in c#):
<ListView x:Name="aktualniGracze" ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="stackLiczymy" Visibility="{Binding isChecked, ElementName=czyLiczymy, Converter={StaticResource BoolToVis}}">
<TextBlock Text="{Binding ileWypil}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
CheckBox:
<CheckBox Name="czyLiczymy"/>
Nothing happens when I change the state of the checkbox, any clues?
Thanks a lot in advance.
If you have your correct DataContext in CheckBox, I think you are just missing the DataContext.isChecked
<ListView x:Name="aktualniGracze" ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="stackLiczymy" Visibility="{Binding DataContext.isChecked, ElementName=czyLiczymy, Converter={StaticResource BoolToVis}}">
<TextBlock Text="{Binding ileWypil}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I have a ListView into which I would like to insert a Expander control as an item (e.g in the third column). What function/method in ListView helps me do this?
You can change the ItemTemplate like this:
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<Expander Header="{Binding Title}">
<TextBlock Text="{Binding Description}" />
</Expander>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>