XAML List view Inside list view - c#

I have this template (c# windows univeral app w8.1)
<ListView ItemsSource="{Binding SelectedSongStanzas}">
<ListView.ItemTemplate>
<DataTemplate>
<ListView ItemsSource="{Binding Verses}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel HorizontalAlignment="Left">
<TextBlock Padding="0" Text="{Binding Harmonization2}" FontFamily="Lucida Console" FontSize="16" Foreground="BlueViolet" VerticalAlignment="Bottom"/>
<TextBlock Padding="0" Text="{Binding OriginalText}" FontFamily="Lucida Console" FontSize="16" VerticalAlignment="Top"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
And This is how it look
If see at image the first list view item shows the first ListItem lines are together with no spaces between them, but the second line shows a big gap between them.
Note:
1) I'm ,was trying with Grid instead stackpanel but looks same way.
2) If Try fixed height texts could be cut.
What can i do to force all ListItems looks the same way?
(Just Like the firs Item)
EDIT ONE: Based on the comments think the problem could be the default styles from windows universal app template. And now could be another question.
How to edit / change / Override those styles on that template ?

Finally as #AnjumSKhan post, the problem wasn't at XAML code, just my structure Has a Literal char \n
Something like this "some text here" was stored as => "\nsome text here", just i remove those new lines literals an now all looks as must be.

Related

Autocomplete combobox vs2017 - properties

I have a problem with combobox. I do not have properties for him. Where can I find AutoComplete properties?
Typing also does not suggest anything to me and as I enter the whole thing, I get the error.
I'm explaining what I mean - I have a combobox with many list records.
I would like the combobox to open, for example, the first three letters.
this is my code of combobox
<ComboBox
x:Name="combolista"
HorizontalAlignment="Left"
Margin="10,384,0,0"
VerticalAlignment="Top"
Width="491"
Grid.Column="1"
SelectionChanged="ComboBox_SelectionChanged"
ItemsSource="{Binding Wyszukanie_miast}"
SelectedItem="{Binding WybraneMiasto}"
IsEditable="True"
TextSearch.TextPath="Miasto">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Miasto}" />
<TextBlock Text="Województwo" Margin="70,0,0,0"/>
<TextBlock Text="{Binding Wojewodztwo}" Margin="150,0,0,0"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
He works but I would like to enter all the possibilities in three letters
you can use telerik : RadAutoCompleteBox if you want, but telerik is not a free library.
you can also take a look at https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit

WP8 Can't show listbox item after using hardware back button

I have two ListBox items: one for show all items and another ListBox for show only selected item and now when I am using hardware back button second ListBox item is not showing?
What do I need to do to allow the ListBox to be selectable/clickable upon return?
Height="72" TextWrapping="Wrap" Name="txtMSG" Text="TextBox" Width="456"/>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="2" Margin="15,10,15,0">
<ListBox Name="list_location" Tap="list_location_Tap" Foreground="Black">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="item_name" Text="{Binding description, Mode=OneWay}" Padding="5,15,5,15" TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeLarge}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox Name="list_locationAdd" Foreground="Black" Visibility="Collapsed">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="item_name" Text="{Binding description, Mode=OneWay}" Padding="5,15,5,15" TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeLarge}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
list_locationAdd.Visibility = Visibility.Visible;
list_location.Visibility = Visibility.Collapsed;
if (!list_locationAdd.Items.Contains(list_location.SelectedItem))
{
list_locationAdd.Items.Add(list_location.SelectedItem);
}
Create XML document and save it to your phone using StorageFile class. Everytime you open your app, it will on launch check your xml file and populate the datagrid. So when you make changes to listboxes it should make changes to xml file too. Next time you quit your application and launch it again, reads data from xml file and then it has the data as it was last time. So my answer is: save your data on phone with xml file.
Save data to phone: https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.aspx
Handling XML documents and elements: https://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument%28v=vs.110%29.aspx

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>

Getting only 3 items of the text block visible on the list

I have a list box that is scrolls horizontally, it has a text block within, am binding data to the text block dynamically , this data is coming from a server,i have folders coming from the server and am displaying only the names of these folders in this list box.suppose there are 10 folders on the start of the App i want only first three names to be visible on the list(the effect should be something like the Panorama page), then when i scroll next three names should be visible and which ever is closest to the middle that folder should get expanded... and which ever name is highlighted for that name the BG of the list box should change to Green.
Please help me out am very new to WP7
the code am using is
<ListBox BorderBrush="White" Background="LightGray" ItemsSource="{Binding DisplayItem}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Disabled" Margin="36,122,34,500" Grid.Row="2">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal">
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Height="75" Width="250" FontSize="28" Foreground="Black" Text="{Binding WidgetName}" HorizontalAlignment="Center">
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
In order to achieve the panorama view, listbox is not your best choice. Code Samples has an example called Panorama/Pivot Sample.
Check it, i think this is what you're looking for, it describes the method used in addition to sample codes.

How to access a TextBlock within a ListBox with C#

For most of you, this might be an easy question, but I am a C# beginner (coming from VB) and would like to progam a Windows Phone App.
The question is: How can I access the TextBlock "LineOne" from code to change its width? For the page title, it works perfect with this (on orientation change):
this.PageTitle.Text = "Portrait";
However, something like this:
this.LineOne.width= "50";
won't work.
Why?
My XAML looks like this (almost the default data bound app from Visual Studio Express):
<!--TitlePanel -->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="PageTitle" Text="Bundesliga" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel -->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox x:Name="MainListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}" SelectionChanged="MainListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="ListboxPanel" Margin="0,0,0,17" Width="432" Orientation="Horizontal">
<TextBlock x:Name="LineOne" Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" Width="40" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Thanks for your help!
You have to access the TextBlocks inside the listbox.
Something like:
TextBlock textblock = ListboxPanel.Items[index] as TextBlock;
textblock.Width = 50
IEnumerable<TextBlock> listtb = ListboxPanel.Items.TypeOf<TextBlock>();
The name can't be resolved as belonging to this as it belongs to the datatemplate. You can't refer to an item within a template (from outside that template) as there could be multiple items with that name and names must be unique.
If you are trying to change the style of the selected item you will likely find a better solution to be to use different visual states to represent this.
If you are trying to access a property which relates to the bound viewmodel you can cast the sender to the type of the viewmodel and access it's properties directly.

Categories

Resources