Error when using <Scrollviewer> xaml - windows-phone-7

I am trying to use a but am getting the error:
The property 'Content' is set more than once.
It dissappears if I remove any one of the two lines of code in between the tags.
So neither of them seems wrong individually, but both together cause the problem.
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="New Trip" Style="{StaticResource PhoneTextNormalStyle}" Height="40" />
<Button Content="Back" Height="71" Name="button1" Width="103" HorizontalContentAlignment="Stretch" VerticalAlignment="Top" HorizontalAlignment="Right" Click="button1_Click" />
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer>
<TextBlock Height="60" HorizontalAlignment="Left" Margin="65,12,0,0" Name="textBlock1" Text="Username" VerticalAlignment="Top" Width="169" />
<TextBox Height="78" HorizontalAlignment="Left" Margin="60,60,0,0" Name="textBoxUsername" VerticalAlignment="Top" Width="274" />
</ScrollViewer>
</Grid>
</Grid>

ScrollViewer can only have 1 content, so wrap the controls inside the ScrollViewer in a container like Grid, DockPanel, StackPanel
<ScrollViewer>
<StackPanel>
<TextBlock Height="60" HorizontalAlignment="Left" Margin="65,12,0,0" Name="textBlock1" Text="Username" VerticalAlignment="Top" Width="169" />
<TextBox Height="78" HorizontalAlignment="Left" Margin="60,60,0,0" Name="textBoxUsername" VerticalAlignment="Top" Width="274" />
</StackPanel>
</ScrollViewer>

Put your <TextBlock> and <TextBox> within another container, such as a StackPanel.

Related

Adaptive List View Help (Windows Universal App)

Below is my xaml code which defines ListView. The output is series of products. But the problem is the product aligns one after another.
I Want an output align vertically one after another.
<ListView x:Name="list" Margin="0,0,0,0" SelectionChanged="list_SelectionChanged" VerticalAlignment="Top">
<ListView.Resources>
<DataTemplate x:Key="myCell">
<Border BorderBrush="Gray" BorderThickness="0,0,0,0" >
<Grid Margin="0" x:Name="tryadpative" >
<Grid.RowDefinitions>
<RowDefinition Height="8*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Image x:Name="prodimg" Width="auto" Source="{Binding prodimg}" Grid.Row="0"></Image>
<TextBlock x:Name="productcode" TextWrapping="Wrap" Text="{Binding productcode}" HorizontalAlignment="Center" Width="auto" FontSize="12" Grid.Row="1" Foreground="Gray"/>
<TextBlock x:Name="productname" FontSize="14" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="Gray" Grid.Row="0" Text="{Binding productname}" />
<TextBlock x:Name="productmindec" TextWrapping="Wrap" HorizontalAlignment="Center" Text="{Binding productmindec}" Width="auto" FontSize="14" Grid.Row="2" Foreground="Gray"/>
<!--<Image x:Name="prodimg" Width="auto" Source="{Binding prodimg}" Grid.Row="0"></Image>
<TextBlock x:Name="productcode" TextWrapping="Wrap" Text="{Binding productcode}" Width="auto" FontSize="12" Foreground="Gray"/>
<TextBlock x:Name="productname" FontSize="14" Foreground="Gray" Text="{Binding productname}" />
<TextBlock x:Name="productmindec" TextWrapping="Wrap" Text="{Binding productmindec}" Width="auto" FontSize="14" Foreground="Gray"/>-->
</Grid>
</Border>
</DataTemplate>
</ListView.Resources>
<!--<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>-->
<ListView.ItemTemplate>
<StaticResource ResourceKey="myCell"/>
</ListView.ItemTemplate>
</ListView>
ItemsStackPanel can be used only as the ItemsPanel of an ItemsControl that displays more than one item at a time. It can't be used with an ItemsControl that displays only one item at a time, such as a ComboBox or FlipView. ItemsStackPanel is the default ItemsPanel for ListView.
By default, the ItemsStackPanel stacks items vertically from top to bottom. You can set the Orientation property to Horizontal to stack items from left to right.
For more info, see ItemsStackPanel.
We should be able to set the Horizontal to the Orientation of the ItemsStackPanel.
For example:
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Horizontal" >
</ItemsStackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
By the way, if you want scroll the ListView in horizontal, you should be able to set the Visible to ScrollViewer.HorizontalScrollBarVisibility and Enabled to the ScrollViewer.HorizontalScrollMode in ListView.
For example:
<ListView x:Name="list"
Margin="0,0,0,0"
SelectionChanged="list_SelectionChanged"
VerticalAlignment="Top"
SelectionMode="Single"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.HorizontalScrollMode="Enabled">
</ListView>

Listview with Horizontal stack panel not scrolling windows 10 universal app

I am trying to build a 4 column list view to display some data in the Windows Universal App. I have the following Listview but the list view is not scrolling vertically in spite of data being there for scroll. I am not sure what I am doing wrong. Any pointers or help is appreciated..
XAML Code
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ChennaiTrains"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ViewModel="using:ChennaiTrains.ViewModel"
xmlns:Model="using:ChennaiTrains.Model"
x:Class="ChennaiTrains.MainPage"
xmlns:c="using:ChennaiTrains.Controls"
mc:Ignorable="d" Loaded="Page_Loaded">
<Page.BottomAppBar>
<CommandBar>
<AppBarButton Icon="Find" Click="AppBarButton_Click"/>
</CommandBar>
</Page.BottomAppBar>
<Page.Background>
<ImageBrush ImageSource="..\Assets\Images\marina.jpg" Stretch="UniformToFill"></ImageBrush>
</Page.Background>
<Grid>
<Grid x:Name="body">
<StackPanel>
<Grid x:Name="titlebar">
<StackPanel Orientation="Horizontal" Background="Transparent">
<Button x:Name="menu"
VerticalAlignment="{x:Bind VerticalContentAlignment}"
HorizontalAlignment="{x:Bind HorizontalContentAlignment}"
FontSize="30"
FontFamily="Segoe MDL2 Assets"
Content="" Click="HamburgerButton_Click"
Background="Transparent" Height="42" Visibility="Visible"/>
<TextBlock x:Name="content"
FontSize="25"
Text="Chennai Compass" Height="42" Visibility="Visible"
VerticalAlignment="{x:Bind VerticalContentAlignment}"
HorizontalAlignment="{x:Bind HorizontalContentAlignment}" Margin="0"/>
</StackPanel>
</Grid>
<SplitView x:Name="MySplitView"
DisplayMode="Inline"
OpenPaneLength="150"
CompactPaneLength="50"
IsPaneOpen="False" Background="Transparent" BorderBrush="Black">
<SplitView.Pane>
<StackPanel Background="Transparent">
<!-- <Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Click="HamburgerButton_Click" /> -->
<StackPanel Orientation="Horizontal" Background="Transparent">
<Button x:Name="MenuButton1" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Visibility="Collapsed"/>
<TextBlock Text="Button 1" FontSize="18" VerticalAlignment="Center" Visibility="Collapsed" />
</StackPanel>
<StackPanel Orientation="Horizontal" Background="Transparent">
<Button x:Name="MenuButton2" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Visibility="Collapsed"/>
<TextBlock Text="Button 2" FontSize="18" VerticalAlignment="Center" Visibility="Collapsed" />
</StackPanel>
<StackPanel Orientation="Horizontal" Background="Transparent">
<Button x:Name="MenuButton3" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Visibility="Collapsed"/>
<TextBlock Text="Button 3" FontSize="18" VerticalAlignment="Center" Visibility="Collapsed" />
</StackPanel>
</StackPanel>
</SplitView.Pane>
<Grid>
<AutoSuggestBox AllowDrop="True" x:Name="fromTextBox"
PlaceholderText="Enter the starting point"
QueryIcon="Find" TextChanged="DestinationBox_TextChanged"
SuggestionChosen="AutoSuggestBox_SuggestionChosen"
QuerySubmitted="AutoSuggestBox_QuerySubmitted"
TextMemberPath="StationName"
>
<AutoSuggestBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="2">
<TextBlock Text="{Binding StationName}" />
</StackPanel>
</DataTemplate>
</AutoSuggestBox.ItemTemplate>
<AutoSuggestBox.DataContext>
<ViewModel:AutoSuggestBoxVM/>
</AutoSuggestBox.DataContext>
</AutoSuggestBox>
<AutoSuggestBox x:Name="DestinationBox"
QueryIcon="Find"
DisplayMemberPath="{Binding StationList.StationName}"
TextMemberPath="StationName"
TextChanged="DestinationBox_TextChanged"
SuggestionChosen="DestinationBox_SuggestionChosen"
PlaceholderText="Enter the destination" Margin="0,60,0,0">
<AutoSuggestBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="2">
<TextBlock Text="{Binding StationName}" />
</StackPanel>
</DataTemplate>
</AutoSuggestBox.ItemTemplate>
<AutoSuggestBox.DataContext>
<ViewModel:AutoSuggestBoxVM/>
</AutoSuggestBox.DataContext>
</AutoSuggestBox>
<Grid x:Name="resultGrid" Margin="0,140,2,0">
<ListView x:Name="resultsList" ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollMode="Enabled" >
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Margin" Value="5"/>
<Setter Property="Padding" Value="15"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.Resources>
<DataTemplate x:Key="TimeTemplate">
<Grid Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Grid.Row="0">
<TextBlock Text="Start at:" Margin="0,0,5,0"></TextBlock>
<TextBlock x:Name="startAt" Text="{Binding Time}" />
<TextBlock FontFamily="Segoe MDL2 Assets" Margin="20,0,5,0" Text="">
</TextBlock>
<TextBlock x:Name="duration" Text="{Binding Duration}"/>
<TextBlock Text="Reach by:" Margin="-212,35,0,0"></TextBlock>
<TextBlock x:Name="EndPoint" Margin="-145,35,0,0" Text="{Binding DestinationTime}" />
<TextBlock FontFamily="Segoe MDL2 Assets"
Text=""
Margin="-75,35,0,0"></TextBlock>
<TextBlock x:Name="trainType" Margin="-55,35,0,0" Text="{Binding TrainType}" />
</StackPanel>
</Grid>
</DataTemplate>
</ListView.Resources>
<ListView.HeaderTemplate>
<DataTemplate>
<TextBlock x:Name="headerText" Text="Next available Trains"/>
</DataTemplate>
</ListView.HeaderTemplate>
<ListView.ItemTemplate>
<StaticResource ResourceKey="TimeTemplate"/>
</ListView.ItemTemplate>
<ListView.DataContext>
<Model:ResultListModel/>
</ListView.DataContext>
</ListView>
</Grid>
</Grid>
</SplitView>
</StackPanel>
</Grid>
</Grid>
</Page>
Your problem is the StackPanel that contains the titlebar and SplitView. Content inside of a StackPanel is not confined to any space and it will stretch on forever. In your case this means the SplitView and therefore the ListView inside it are stretching forever. Without being confined the ListView doesn't believe it needs to scroll.
The fix is to use a Grid with Rows instead. I would add Grid RowDefinitions into your body Grid with the titlebar in row 0 and the SplitView in row 1 and remove the StackPanel just inside the body Grid. That will get your scrolling working. Paraphrasing your code, the row definitions would look like this
<Grid x:Name="body">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid x:Name="titlebar" Grid.Row="0">
</Grid>
<SplitView x:Name="MySplitView" Grid.Row="1">
</SplitView>
</Grid>

GridView Items does not have same height

I have a GridView that displays Header and Sub-Items like so:
<GridView ItemsSource="{Binding Path=MainViewModels}">
<GridView.ItemTemplate>
<DataTemplate>
<Grid VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border BorderBrush="White" BorderThickness="1"></Border>
<Grid VerticalAlignment="Top" HorizontalAlignment="Left">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="White" BorderThickness="1"></Border>
<TextBlock Grid.Row="0"
HorizontalAlignment="Left"
Foreground="#FFAAAAAA"
Style="{StaticResource Style_TextBlock_Label_H3}"
Text="{Binding Path=Description}" VerticalAlignment="Top" />
<GridView Grid.Row="1"
ItemsSource="{Binding Path=SubViewModels}">
<GridView.ItemTemplate>
<DataTemplate>
<TextBlock Margin="0,0,5,0"
Text="{Binding Path=Description}"
TextWrapping="Wrap" />
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Vertical" VerticalAlignment="Stretch" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
</Grid>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Top">
</StackPanel>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
However, whenever it renders, it renders like this:
What I want to achieve is that all the "Header" are on the top, while the Items themselves extend to the bottom and then just overflow using the WrapGrid.
Can please point out where I am going wrong?
Thank you!

Why Does Blend Fail To Show Text in Generated Item Template?

I am trying to get some design data in blend expressions for my wp7 app but after a certain point it seems to just lose the data and shows me nothing
As you can see I see nothing in the rectangle error even though there is a hardcoded value in it.
<Grid x:Name="LayoutRoot"
Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentGrid"
Grid.Row="1">
<ListBox x:Name="lbMovieCollection" ItemsSource="{Binding MovieCollections}">
<ListBox.Resources>
<DataTemplate x:Key="lbMovieCollectionItemTemplate">
<toolkit:ExpanderView x:Name="expMovieCollection" ItemsSource="{Binding Movies}" Header="{Binding Mode=OneWay}" Width="480">
<toolkit:ExpanderView.Resources>
<DataTemplate x:Key="expMovieCollectionHeaderTemplate">
<TextBlock TextWrapping="Wrap" Text="{Binding Name}" Height="50"/>
</DataTemplate>
<DataTemplate x:Key="expMovieCollectionItemTemplate">
<ListBoxItem HorizontalAlignment="Left" toolkit:TiltEffect.IsTiltEnabled="True" d:LayoutOverrides="VerticalAlignment">
<StackPanel Height="61" Width="371" >
<TextBlock TextWrapping="Wrap" Text="THIS IS HARCDOED" FontSize="29.333" />
</StackPanel>
</ListBoxItem>
</DataTemplate>
</toolkit:ExpanderView.Resources>
<toolkit:ExpanderView.ItemTemplate>
<StaticResource ResourceKey="expMovieCollectionItemTemplate"/>
</toolkit:ExpanderView.ItemTemplate>
<toolkit:ExpanderView.HeaderTemplate>
<StaticResource ResourceKey="expMovieCollectionHeaderTemplate"/>
</toolkit:ExpanderView.HeaderTemplate>
</toolkit:ExpanderView>
</DataTemplate>
</ListBox.Resources>
<ListBox.ItemTemplate>
<StaticResource ResourceKey="lbMovieCollectionItemTemplate"/>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
Looks like your "THIS IS HARCDOED" values are hidden inside the collapsed portion of toolkit:ExpanderView control.

memory leak in window phone 7

I tried to control the memory in our application. But the memory is not the same as when a new application starts.
Example:
In app, I have 2 Pages (MainPage.xaml and Page1.xaml).
Code in MainPage(.Xaml):
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="147,223,0,0" Name="button1" VerticalAlignment="Top" Width="160"/>
</Grid>
</Grid>
and Page1.xaml :
<Grid x:Name="LayoutRoot" Background="Transparent">
<Button Content="add" Height="72" HorizontalAlignment="Left" Margin="41,12,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
<Button Content="remove" Height="72" HorizontalAlignment="Left" Margin="240,12,0,0" Name="button2" VerticalAlignment="Top" Width="160" Click="button2_Click" />
<ListBox Height="666" HorizontalAlignment="Left" Margin="12,90,0,0" Name="lsbMyList" VerticalAlignment="Top" Width="456" />
</Grid>
Page1: when I returned from the memory MainPage, my application increased from 1Mb to over 5Mb.
In listbox of Page1, I add an Image to listBox, when I Back Page , I set the image control to null URL and imageControl = null; memory is not reduced
Can anyone point me in the right direction?
See instructions on releasing image memory at http://blogs.msdn.com/b/swick/archive/2011/04/07/image-tips-for-windows-phone-7.aspx
How are you confirming that the memory is from the image and not anything else you're using and possibly not clearing up?

Resources