c# WPF How to Remove listview header seperator line? - c#

How to Remove this header seperator line
<ListView ItemsSource="{Binding ...}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
...
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
this is my ListView

Unless I'm missing something, is this not just a matter of setting the BorderThickness property to zero on your ListView?
<ListView ItemsSource="{Binding}" BorderThickness="0">
That should be the solution given the information provided in your question.
If you define some container in your ItemTemplate that has a border, the solution would be similar.

Related

How to create a template with parameters in WPF?

I have 3 List views. They are very similar. The only difference is that their ItemsSource binds to different variables. Is there a way to create a template list view with unknown ItemsSource, and I can pass a parameter to fill that ItemsSource?
My code is something like this:
<ListView Name="View1" ItemsSource={"Binding Student1"}>
<TextBlock Text={"Binding Name"}/>
</ListView>
<ListView Name="View2" ItemsSource={"Binding Student2"}>
<TextBlock Text={"Binding Name"}/>
</ListView>
<ListView Name="View3" ItemsSource={"Binding Student3"}>
<TextBlock Text={"Binding Name"}/>
</ListView>
Edit:
I might have expressed my question in a wrong way. I would like to have a separate user control view called "StudentView":
<ListView ItemsSource=Parameter1>
<TextBlock Text={"Binding Name"}/>
</ListView>
So that in my main window, I can do something like this:
<local:StudentView Parameter1={"Binding Student1"}/>
You are on the right track with thinking about templating
What you are looking for is something called a ControlTemplate.
Your ControlTemplate would then target the ListView control and use the key word TemplateBinding to pass through the ItemsSource binding from your ListView
You would look to add this as a window resource as shown below.
<Window.Resources>
<ControlTemplate x:Key="ListViewTemplate" TargetType="ListView">
<ListView ItemsSource="{TemplateBinding ItemsSource}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ControlTemplate>
</Window.Resources>
This would enable you to use this template on your ListView controls as shown below
<ListView Template="{StaticResource ListViewTemplate}" ItemsSource="{Binding PersonList}"/>
<ListView Template="{StaticResource ListViewTemplate}" ItemsSource="{Binding PersonList1}"/>
<ListView Template="{StaticResource ListViewTemplate}" ItemsSource="{Binding PersonList2}"/>
Hope this gives you what you were looking for

Textbox in Listview not expand until hover a mouse over it

So I have a list that loads a data from a list of string.
I want to make it editable, So I make a ListView of Textbox.
Somewhat like this:
<ListView ItemsSource="{x:Bind texts, Mode=TwoWay}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<TextBox Text={Binding, Mode=TwoWay}>
<Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
The problem is that when the list is loaded. If it already has a text. It collapsed.
Here's a picture for the context..
Is there a way to fix it?
Setting a MinHeight on the TextBox element should fix the problem.

UWP targeting listview item template property

i'm trying to make my App Design responsive.
i have ListView that have a dataTemplate with defined property:
<ListView x:Name="listView" ItemsSource="{x:Bind manager.recentVideos}"
IsItemClickEnabled="True"
ItemClick="ListView_ItemClick">
<ListView.ItemTemplate>
<DataTemplate x:DataType="data:VideoItem" >
<Image Width="200"
Source="{x:Bind TileImage}" Margin="-10,0,-10,5"
></Image>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I'm trying to change Image Width with VisualStateTrigers...
so i need to Target Setter to this property somehow....
Someone please help! :)
VisualStateTriggers are not supported inside DataTemplates. Just use a UserControl as your DataTemplate as is suggested in this:
AdaptiveTrigger and DataTemplate

XAML Element Alignment issue

I have a list view that will contain notes that I input. I am having trouble figuring out how to have the list view item look how I want it to.
Below is how it should look:
And this is what it currently looks like:
How do I write the list view item in XAML so that the Date and time appear to the very top-right of each list view item, with the text of the note to the left?
<ListView x:Name="list" ItemsSource="{Binding Note}" BorderBrush="{x:Null}" BorderThickness="0">
<DataTemplate>
<ListViewItem>
<StackPanel Orientation="Horizontal">
</StackPanel>
</ListViewItem>
</DataTemplate>
</ListView>
Any help at all is much appreciated!
You are missing a number of elements required in order to get your screen to look the way you want.
You need to define the ItemTemplate for the ListView. You're on the right track here, it is a DataTemplate declared in XAML, you just have to apply it to the ListView.ItemTemplate property.
You need to set the HorizontalContentAlignment of the ListView to Stretch (the default is Left, which means your items will not fill the entire content area).
You need to use a DockPanel (or other similar panel) inside your DataTemplate to place your date content on the right, and the remainder of your content on the left.
You need to disable Horizontal Scrolling (ScrollViewer.HorizontalScrollBarVisbility) on the ListView in order to make your content wrap (otherwise it will just happily draw it all on one line).
I've included a sample ListView that should get you started.
<ListView
ItemsSource="{Binding Items}"
HorizontalContentAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock
TextWrapping="Wrap"
Text="{Binding Date}"
Background="Magenta"
DockPanel.Dock="Right" />
<TextBlock Text="{Binding Content}" Background="Lime" />
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

Using * sizing in a data template WPF

I am trying to set a * height property in an item template but I keep getting the error
'50*' string cannot be converted to Length.
Im not sure if what Im wanting to do is possible.
Please let me know if you need anymore information.
Heres my Xaml:
<ItemsControl Name="lstMain" ItemsSource="{Binding Sections}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<GroupBox Header="{Binding Section.SectionName}" Height="50*">
<StackPanel>
<ItemsControl ItemsSource="{Binding SubSections}" ItemTemplate="{StaticResource BinderTemplate}" />
</StackPanel>
</GroupBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
the point is that Height is a Double data type and not a GridLength, such as grid rows and columns are.
Only GridLength supports the star size.

Categories

Resources