Text not wrapping in ListViewItem - c#

The ListViewItems are getting their width from the TextBlock element. I want the ListViewItem to fit to the ListView. I have seen in other posts that making HorizontalContentAlignment="Stretch" will fix the issue, but my problem persists. The second TextBlock element in the ItemTemplate is set to WrapWithOverflow.
Sources:
http://www.teixeira-soft.com/bluescreen/2016/03/21/c-how-to-make-a-panel-within-a-datatemplate-fill-the-entire-width-of-a-listview-or-itenscontrol-derivative/
Code:
<UserControl x:Class="XXXX.Views.XXXXView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cal="http://www.caliburnproject.org"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="{StaticResource BlackBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="32*"/>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="32*"/>
</Grid.ColumnDefinitions>
<DockPanel Grid.Column="1">
<ListView Grid.Column="1"
x:Name="UniqueShortDescriptions"
VerticalAlignment="Stretch"
ItemsSource="{Binding UniqueShortDescriptions}"
SelectedItem="{Binding SelectedUniqueShortDescriptions}"
cal:Message.Attach="[Event SelectionChanged] = [Action SelectionChanged($this, $eventArgs)]">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Navy"
BorderThickness="3"
Margin="3"
Padding="2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Grid.RowSpan="3"
Grid.Column="0"
Text="{Binding Path=Date}"
Foreground="Black"
VerticalAlignment="Center"
TextBlock.FontWeight="ExtraBold"/>
<TextBlock Grid.Row="0"
Grid.Column="1"
Text="{Binding Path=LongDescription}" Foreground="{StaticResource BlackBrush}"
TextWrapping="WrapWithOverflow"/>
<!--<TextBlock Text="{Binding Path=ShortExpenseDescription}" Foreground="{StaticResource BlackBrush}"/>-->
<TextBlock Grid.Row="1"
Grid.Column="1"
Text="{Binding Path=Cost}" Foreground="{StaticResource BlackBrush}"/>
<TextBlock Grid.Row="2"
Grid.Column="1"
Text="{Binding Path=Source}" Foreground="{StaticResource BlackBrush}"/>
</Grid>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DockPanel>
</Grid>
</UserControl>

I got the code you posted to work by simply disabling horizontal scrolling of the ListView.
<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled" ...

Related

How can I improve the layout for this Input Screen?

Right now I have this XAML layout for my WPF application:
<Window x:Class="Cabrillo_Editor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Cabrillo_Editor"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_Exit" Click="ExitApplication"/>
<MenuItem Header="_New"/>
<MenuItem Header="_Save" Click="SaveCabrilloFile"/>
</Menu>
<StackPanel>
<GroupBox Height="Auto" Header="General">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="185"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="5"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" Grid.Column="0" Margin="0,0,0,5">
<Label>My Call:</Label>
<TextBox Width="120" Name="CallsignTextBox" HorizontalAlignment="Right" CharacterCasing="Upper"/>
</DockPanel>
<DockPanel Grid.Row="2" Grid.Column="0">
<Label>My Grid:</Label>
<TextBox Width="120" Name="GridTextBox" HorizontalAlignment="Right"/>
</DockPanel>
<DockPanel Grid.Row="0" Grid.Column="2">
<Label>Contest:</Label>
<ComboBox Width="150" Name="ContestComboBox" Margin="5,0,0,0"/>
</DockPanel>
<DockPanel Grid.Row="2" Grid.Column="2">
<Label>Assisted:</Label>
<CheckBox VerticalAlignment="Center" Name="AssistedCheckBox" Margin="5,0,0,0"/>
</DockPanel>
<DockPanel Grid.Row="0" Grid.Column="4">
<Label>Band:</Label>
<ComboBox Width="150" Name="BandComboBox" Margin="5,0,0,0"/>
</DockPanel>
</Grid>
</GroupBox>
</StackPanel>
</DockPanel>
</Window>
And it looks like this:
Why, for example, is are the ComboBoxes so streched if I set the row height to "Auto" (same for the TextBoxes)?
Is there a better way to make consistent horizontal space between the columns?
This is occurring because those controls will stretch to fill their parent container by default. To override this, simply set the VeriticalAlignment property and Height property (if needed).
<ComboBox Width="150" Name="ContestComboBox" Margin="5,0,0,0" VerticalAlignment=Top/>

WPF a scrollviewer in an itemscontrol in a groupbox not showing all items

I've an usercontrol with a groupbox where there's an itemscontrol in it.
Within the itemscontrol I put an scrollviewer.
When I run the application it isn't showing all the items.
Sometimes I see 1 or 2 items, sometimes nothing.
I'am certain that my list has at least 10 items in it.
What am I doing wrong here?
I've put the scrollviewer in the itemscontrol like described here:
WPF: ItemsControl with scrollbar (ScrollViewer)
<UserControl x:Class="Hermes.UI.HistoryListControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml /presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Hermes.UI"
mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="800" d:DataContext="{x:Static local:HistoryListDesignModel.Instance}">
<GroupBox Margin="5 0"
Padding="4"
BorderBrush="{StaticResource clr_dark_brush}"
BorderThickness="0.5">
<GroupBox.Header>
<Label Content="Geschiedenis"
FontFamily="{StaticResource NunitoBold}"
FontSize="{StaticResource FontSizeRegular}"
Foreground="{StaticResource clr_dark_brush}"/>
</GroupBox.Header>
<ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer x:Name="ScrollViewer" Padding="{TemplateBinding Padding}">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:HistoryListItemControl />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</GroupBox>
</UserControl>
and hen the local:HistoryListItemControl
<UserControl x:Class="Hermes.UI.HistoryListItemControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Hermes.UI"
mc:Ignorable="d" d:DesignWidth="800">
<UserControl.Resources>
<Style x:Key="contentstyle" TargetType="{x:Type ContentControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
<Border x:Name="background"
Background="White"
Margin="0 5">
<Grid x:Name="container" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{Binding date_cal, StringFormat='dd MMMM yyyy'}"
FontSize="{StaticResource FontSizeLarge}"
FontFamily="{StaticResource NunitoThin}"
Foreground="{StaticResource clr_info_brush}"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock FontFamily="{StaticResource FontAwesome}"
VerticalAlignment="Center"
Margin="5"
Text="" />
<TextBlock Text="{Binding Device_name}"
VerticalAlignment="Center"
Grid.Column="1"/>
<TextBlock FontFamily="{StaticResource FontAwesome}"
VerticalAlignment="Center"
Margin="5"
Text=""
Grid.Column="2"/>
<TextBlock Text="{Binding Unit_name}"
VerticalAlignment="Center"
Grid.Column="3"/>
</Grid>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock FontFamily="{StaticResource FontAwesome}"
VerticalAlignment="Center"
Margin="5"
Text="" />
<TextBlock Text="{Binding Sensor}"
VerticalAlignment="Center"
Grid.Column="1"/>
<TextBlock FontFamily="{StaticResource FontAwesome}"
VerticalAlignment="Center"
Margin="5"
Text=""
Grid.Column="2"/>
<TextBlock Text="{Binding Battery}"
VerticalAlignment="Center"
Grid.Column="3"/>
</Grid>
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock FontFamily="{StaticResource FontAwesome}"
VerticalAlignment="Center"
Margin="5"
Text="" />
<TextBlock Text="{Binding Comments}"
VerticalAlignment="Center"
Grid.Column="1"/>
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<ContentControl d:DataContext="{x:Static local:HistoryListItemDesignModel.Instance}"
Style="{StaticResource contentstyle}" />
</UserControl>
The items are loaded in with a viewmodel and is called from within the constructor of the viewmodel:
private void GetHistory()
{
HistoryBLL historyBLL = new HistoryBLL();
HistoryDataTable myHistory = historyBLL.GetHistoryByDeviceId(Device.Id);
foreach (HistoryRow row in myHistory)
{
UnitsBLL unitsBLL = new UnitsBLL();
Items.Add(new HistoryListItemViewModel
{
Date_cal = (DateTime)row.date_cal,
Device_name = row.tagnaam,
Unit_name = unitsBLL.GetUnitById(row.unit_id).unit,
Sensor = row.sensor_id.ToString(),
Battery = (row.battery) ? "Ja" : "",
Comments = row.comments
});
unitsBLL = null;
}
}
When I put a breakpoint at the last line I can see that the List of Items is filling up with at least 10 items, so that part is working.
I expect to see all the items and not just 1 or 2 (of even nothing)

UWP C# - Problems with Grid in a Listview

I am writing a little app in C# for windows 10, and I have a listview as below, which is already in a grid.
However the grid I am adding to the listview doesn't expand out to fill the space, it is just grows as wide as the length of the data contained in the field bound to it. What am I doing wrong? I don't want to use fixed fields, I'd prefer to use a relative proportion of the page width.
Help!
<Grid x:Name="RootGrid" Margin="5" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="FolderMate" Style="{StaticResource SampleHeaderTextStyle}"/>
<Button x:Name="GetFilesAndFoldersButton"
Grid.Row="1"
Grid.Column="0"
Content="Get files and folders"
Click="GetFilesAndFoldersButton_Click"
Margin="0,10,0,10"/>
<TextBlock x:Name="FileInfo"
Grid.Row="1"
Grid.Column="1"
Grid.ColumnSpan="3"
VerticalAlignment="Center"
Margin="10"
Foreground="Green"/>
<Button x:Name="ResetButton"
Grid.Row="1"
Grid.Column="5"
Content="reset"
HorizontalAlignment="Right"
Click="ResetButton_Click"
Margin="0,10,10,0"/>
<!--<ScrollViewer VerticalScrollMode="Auto"
VerticalScrollBarVisibility="Auto"
Grid.Row="2"
Grid.ColumnSpan="5"
BorderBrush="Black"
BorderThickness="2"
Background="Chartreuse"
Margin="0,5,0,5">-->
<ListView x:Name="ThisList"
Grid.Row="2"
Grid.ColumnSpan="5"
Background="LightBlue"
Margin="5"
IsItemClickEnabled="True"
ItemClick="ThisList_ItemClick">
<ListView.ItemTemplate>
<DataTemplate>
<Grid BorderThickness="1" BorderBrush="Red" >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Background="Aquamarine" Grid.Column="0">
<SymbolIcon Symbol="Folder" HorizontalAlignment="Center" Margin="15 0"/>
</Border>
<Border Background="Yellow" Grid.Column="1">
<TextBlock Text="{Binding FName}" Margin="10" />
</Border>
<Border Background="Cyan" Grid.Column="2">
<TextBlock Text="{Binding FTime}" Margin="10"/>
</Border>
<Border Background="Tomato" Grid.Column="3">
<TextBlock Text="{Binding FSize}" HorizontalAlignment="Right" Margin="10"/>
</Border>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<!--</ScrollViewer>-->
</Grid>
You need to set the HorizontalContentAlignment inside ListView.ItemContainerStyle for ListViewItem to Stretch.
Your Full XAML For ListView will be like below.
<ListView x:Name="ThisList"
Grid.Row="2"
Grid.ColumnSpan="5"
Background="LightBlue"
Margin="5"
ItemsSource="{Binding data}"
IsItemClickEnabled="True"
ItemClick="ThisList_ItemClick">
<ListView.ItemTemplate>
<DataTemplate>
<Grid BorderThickness="1" BorderBrush="Red" >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Background="Aquamarine" Grid.Column="0">
<SymbolIcon Symbol="Folder" HorizontalAlignment="Center" Margin="15 0"/>
</Border>
<Border Background="Yellow" Grid.Column="1">
<TextBlock Text="{Binding FName}" Margin="10" />
</Border>
<Border Background="Cyan" Grid.Column="2">
<TextBlock Text="{Binding FTime}" Margin="10"/>
</Border>
<Border Background="Tomato" Grid.Column="3">
<TextBlock Text="{Binding FSize}" HorizontalAlignment="Right" Margin="10"/>
</Border>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
See in the end, How I added ItemContainerStyle Targeting Only ListViewItem.
Final Output will be
Good Luck.
Might be it will helpful for you. I had used like that-
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto">
<StackPanel>
<ListView x:Name="UserMessageList">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local1:MessageModel">
<StackPanel>
//Add your conrole
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</ScrollViewer>

how to update xaml in uwp

I have created a application for windows 10 (uwp) devices. I´m using the windows appstudio "designer". Now, I have to update the source code by a combobox and the correct eventhandler.
The combobox items contains different urls. After the selection changed, I have to parse entries from a url.
Layout-file:
<Page
x:Class="App.Pages.NeuigkeitenListPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:was_actions="using:AppStudio.Uwp.Actions"
xmlns:was_commands="using:AppStudio.Uwp.Commands"
xmlns:was_controls="using:AppStudio.Uwp.Controls"
xmlns:list_layouts="using:Wallfahrtsapp.Layouts.List"
xmlns:controls="App.Layouts.Controls"
xmlns:vm="using:App.ViewModels"
xmlns:triggers="using:App.Triggers"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
d:DataContext="{d:DesignData Source=/Assets/Design/DesignData.json, Type=vm:DesignViewModel, IsDesignTimeCreatable=true}"
mc:Ignorable="d">
<Page.Resources>
<was_controls:VisualBreakpoints x:Name="ResponsiveBehaviorsVBP" ConfigFile="/Assets/ResponsiveBehaviorsVBP.json"></was_controls:VisualBreakpoints>
</Page.Resources>
<Grid Background="{StaticResource AppBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.ColumnSpan="2" Background="{StaticResource AppBarBackground}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="48"/>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="{Binding Active.pageTitleMargin, Source={StaticResource ResponsiveBehaviorsVBP}}" Text="{x:Bind ViewModel.PageTitle}" Foreground="{StaticResource AppBarForeground}" FontSize="{StaticResource AppTitleTextSizeDefault}" VerticalAlignment="Center" HorizontalAlignment="Left" TextTrimming="CharacterEllipsis" MaxLines="1"/>
<was_actions:ActionsCommandBar
x:Name="appBar"
ActionsSource="{x:Bind ViewModel.Actions}" Style="{StaticResource WasCommandBarStyle}"
Foreground="{StaticResource AppBarForeground}"
IsVisible="{x:Bind ViewModel.HasActions}"
Background="{StaticResource AppBarBackground}"
Grid.Row="{Binding Active.appBarRow, Source={StaticResource ResponsiveBehaviorsVBP}}"
Grid.Column="{Binding Active.appBarColumn, Source={StaticResource ResponsiveBehaviorsVBP}}"
Grid.ColumnSpan="{Binding Active.appBarColumnSpan, Source={StaticResource ResponsiveBehaviorsVBP}}" Opened="appBar_Opened">
</was_actions:ActionsCommandBar>
<ScrollViewer Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="3"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ProgressBar Grid.Row="1" Height="3" Margin="0,6,0,6" IsIndeterminate="True" Foreground="{StaticResource PageTitleForeground}" Visibility="{x:Bind ViewModel.IsBusy, Converter={StaticResource BoolToVisibilityConverter}, FallbackValue=Collapsed, Mode=OneWay}"/>
<was_controls:ErrorNotificationControl x:Uid="ListErrorNotificationControl" Grid.Row="2" ErrorVisibility="{x:Bind ViewModel.HasLoadDataErrors, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}" ErrorColor="{StaticResource PageTitleForeground}" Margin="10,0,18,0"/>
<list_layouts:ListContactCard Grid.Row="1" ItemsSource="{x:Bind ViewModel.Items, Mode=OneWay}" ItemClickCommand="{x:Bind ViewModel.ItemClickCommand}" OneRowModeEnabled="False" Margin="31,0,0,3" Grid.RowSpan="3" />
<ListBox></ListBox>
</Grid>
</ScrollViewer>
<TextBlock HorizontalAlignment="Left"
x:Name="source"
TextWrapping="Wrap"
Text="Newsquelle auswählen:"
VerticalAlignment="Top"
FontFamily="Segoe UI"
FontStyle="Oblique"
Padding="40" Margin="384,-30,0,0" Height="78"
/>
<ComboBox x:Name="sourceComboBox"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Width="200"
SelectionChanged="selectionChanged"
>
<ComboBoxItem Content="Url1"/>
<ComboBoxItem Content="Url2"/>
</ComboBox>
<controls:DataUpdateInformationControl Grid.Row="2" Grid.ColumnSpan="2" LastUpdateDateTime="{x:Bind ViewModel.LastUpdated, Mode=OneWay}" Color="{StaticResource PageTitleForeground}" Margin="8,4,8,4" HorizontalAlignment="Left" HasLocalData="{x:Bind ViewModel.HasLocalData}"/>
</Grid>
C#- file: Eventhandler
private void selectionChanged (object sender , SelectionChangedEventArgs args)
{
index = sourceComboBox.SelectedIndex;
Debug.WriteLine("selectionChangedEventMethod");
newsblogHTTP(index);
}
But how can I update my layout with the new content?
If you need more code snippets let´s see the repo for my project.
layout-file : https://github.com/MasterCoder1992/BlutWallfahrtWindows10/blob/version/march2k17Y/Wallfahrtsapp.W10/Pages/NeuigkeitenListPage.xaml
https://github.com/MasterCoder1992/BlutWallfahrtWindows10/blob/version/march2k17Y/Wallfahrtsapp.W10/Pages/NeuigkeitenListPage.xaml.cs
C#-Config file:
https://github.com/MasterCoder1992/BlutWallfahrtWindows10/blob/version/march2k17Y/Wallfahrtsapp.W10/Sections/NeuigkeitenConfig.cs
Thanks for your help!

find index of StackPanel in dynamically filled Listview in WPF

I am trying to find the index of the StackPanel in an ListView which is filled with an binding to public ObservableCollection<Artikel> Artikels { get; set; } = new ObservableCollection<Artikel>();.
<Window x:Class="KassaBlokboek.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:KassaBlokboek"
mc:Ignorable="d"
WindowState="Maximized" ResizeMode="NoResize"
WindowStyle="None" WindowStartupLocation="CenterScreen"
Title="MainWindow" Height="350" Width="525"
MinWidth="768"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="7*"/>
</Grid.RowDefinitions>
<Image Source="Resources/LogoNew.jpg" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Left"></Image>
<TextBox PreviewTextInput="TextBox_OnPreviewTextInput" Name="TextBox" KeyDown="ProductScanned" HorizontalAlignment="Center" Grid.Row="0" Width="768" Height="64" VerticalAlignment="Bottom" Margin="0,-25,0,5"></TextBox>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="5*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Click="ScrollUp" x:Name="HoofdButton" Grid.Row="0" Grid.Column="0">Product naar boven</Button>
<ListView ScrollViewer.VerticalScrollBarVisibility="Hidden" x:Name="listView" Grid.Row="0" Grid.RowSpan="5" Grid.Column="1"
ItemsSource="{Binding Artikels}">
<ListView.ItemTemplate>
<DataTemplate DataType="local:Artikel">
<Grid Height="{Binding ElementName=HoofdButton, Path=ActualHeight}" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Text="{Binding Naam}"></TextBlock>
<TextBlock Text="{Binding Prijs, StringFormat=€0.00}"></TextBlock>
<TextBlock Text="{Binding Barcode}"></TextBlock>
<TextBlock Text="{Binding Aantal}"></TextBlock>
</StackPanel>
<Button Click="Verwijder" Grid.Column="1">Verwijder</Button>
<Button Click="WijzigAantal" Grid.Column="2" Margin="25,0,0,0">Aantal</Button>
<Button Click="VerhoogAantal" Grid.Column="3" Margin="25,0,0,0">+</Button>
<Button Click="VerlaagAantal" Grid.Column="4" Margin="25,0,0,0">-</Button>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
<Button Click="ScrollDown" Grid.Row="4" Grid.Column="0">Product naar beneden</Button>
<StackPanel Grid.Row="5" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
<Button Click="BetaalContant" Width="128">Contant</Button>
<Button Width="128" Margin="25,0,0,0" Click="BetaalPinnen">Pinnen</Button>
<Button Width="128" Margin="25,0,0,0" Click="Retour">Retour</Button>
</StackPanel>
<TextBlock x:Name="totaalPrijs" Margin="10,9.8,0,0" Grid.Row="5" Grid.Column="0" Text="Totaalprijs: €0.00"/>
</Grid>
</Grid>
</Window>
I need to find the index of the StackPanel, so i can edit the text in the "Aantal" TextBlock in the StackPanel.

Categories

Resources