Command Is not executing from ItemsControl in Silverlight 5 MVVM - xaml

I Have Used ItemsControl and added this in wrappanel.
<toolkit:WrapPanel Height="Auto" Width="Auto" Orientation="Horizontal" >
<ItemsControl ItemsSource="{Binding ParcelViewModel.FavoriteParcelImages}" Height="Auto" Width="Auto" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Grid.Column="2" Grid.Row="1" Grid.RowSpan="3" Height="Auto" Width="Auto" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1" BorderBrush="LightGray" Margin="3" Height="Auto" Width="200" >
<StackPanel Orientation="Horizontal" Width="200">
<Grid Width="200">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Height="100" HorizontalAlignment="Left">
<!--<Image Source="/PropMgmt;component/Assets/Images/office-building-icon.png" Margin="0,5,0,0" Width="50" Height="50" />-->
<Image Source="{Binding DisplayImage.Source}" Height="50" Width="50"></Image>
<StackPanel Margin="15,0,0,0">
<StackPanel Orientation="Horizontal">
<Image Source="/PropMgmt;component/Assets/Images/circle_orange.png" Width="10" />
<TextBlock Text="{Binding ReservedCount}" Margin="5,0,0,0"></TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Image Source="/PropMgmt;component/Assets/Images/circle_green.png" Width="10" />
<TextBlock Text="{Binding VaccantCount}" Margin="5,0,0,0"></TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Image Source="/PropMgmt;component/Assets/Images/circle_red.png" Width="10" />
<TextBlock Text="{Binding LeasedCount}" Margin="5,0,0,0"></TextBlock>
</StackPanel>
</StackPanel>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1">
<TextBlock Text="Code:" FontWeight="Bold"></TextBlock>
<TextBlock Text="{Binding Code}"></TextBlock>
<TextBlock Text="Name:" FontWeight="Bold"></TextBlock>
<TextBlock Text="{Binding Title}"></TextBlock>
**<HyperlinkButton Content="{Binding Title}" Command="{Binding GetUnitListForParcel}" ></HyperlinkButton>**
<TextBlock Text="Year of Construction:" FontWeight="Bold"></TextBlock>
<TextBlock Text="{Binding Year_Of_Construction}"></TextBlock>
</StackPanel>
</Grid>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</toolkit:WrapPanel>
Added Hyperlink Button Inside DataTemplate. But I Didnt Understand Why Command On HyperlinkButton Is Not working??
Please Help..

you need to change your binding:
<HyperlinkButton Content="{Binding Title}" Command="{Binding YourViewModelName.GetUnitListForParcel, Source={StaticResource Locator}}" />

Related

2 DataTemplates within each other, Command not found

My ICommand is not firing when i touch my button...
I have a DataTemplate within a DataTemplate... does DataContext still refer to the entire page or is it that DataContext refers to the previous DataTemplate and that's why it cannot find my view model's ICommand?
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Top">
<Border BorderThickness="0 0 0 2" BorderBrush="{StaticResource xLightGray}" Margin="0,0,0,10" Padding="0,0,0,10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Background="Transparent">
<Border Background="White" BorderThickness="0" Width="40" Height="40" HorizontalAlignment="Left">
<Image Source="{Binding image.thumbnail_link}" Width="40" Height="40"></Image>
</Border>
</StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Center" Background="Transparent">
<TextBlock Text="{Binding name}" HorizontalAlignment="Left" FontSize="30" VerticalAlignment="Center" Padding="10,0,0,0" />
</StackPanel>
</Grid>
</Border>
<phone:LongListSelector x:Name="OrganisationItemList"
Background="Transparent"
ItemsSource="{Binding spaces}"
LayoutMode="List"
VerticalContentAlignment="Stretch">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Button Background="Red" Style="{StaticResource xTransparentButton}" Command="{Binding Path=DataContext.LoadSpaceCommand, ElementName=SpaceList}" CommandParameter="{Binding}" Padding="0,0,0,5" Margin="0" Height="auto" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Stretch" HorizontalContentAlignment="Left" UseLayoutRounding="True" FontSize="0.01">
<StackPanel Grid.Column="1" VerticalAlignment="Center" Background="Transparent">
<TextBlock Padding="0,0,0,0" Text="{Binding name}" HorizontalAlignment="Left" FontSize="{StaticResource xFontSize}" />
</StackPanel>
</Button>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
Found the answer, you must set ElementName in the binding to the parent ListBox:
Command="{Binding Path=DataContext.LoadSpaceCommand, ElementName=OrganisationList}"

ExpanderView not showing controls inside it

In the below XAML, I am able to see the controls inside the expanderview on expanding which is on GridRow 6 but not able to see any controls inside the expanderview which is on GridRow 0. Can anyone help me as to what am I missing here?
<Grid x:Name="ContentPanel" Margin="0,50,0,1" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="0"></RowDefinition>
<RowDefinition Height="Auto" MinHeight="0"></RowDefinition>
<RowDefinition Height="Auto" MinHeight="0"></RowDefinition>
<RowDefinition Height="Auto" MinHeight="0"></RowDefinition>
<RowDefinition Height="Auto" MinHeight="0"></RowDefinition>
<RowDefinition Height="Auto" MinHeight="0"></RowDefinition>
<RowDefinition Height="Auto" MinHeight="0"></RowDefinition>
<RowDefinition Height="Auto" MinHeight="0"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Vertical" VerticalAlignment="Top">
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
<Image x:Name="img1" VerticalAlignment="Top" Height="40" Width="40" HorizontalAlignment="Left" Margin="10,92,0,0" Source="Images/1.png" Visibility="Collapsed" Canvas.ZIndex="3"></Image>
<TextBlock x:Name="tbScore" VerticalAlignment="Top" HorizontalAlignment="Left" Foreground="White" Width="Auto" Margin="-32,97,0,0" FontFamily="TypeFace" FontSize="18" Canvas.ZIndex="3"/>
<Image x:Name="img1" Height="90" Margin="-23,20,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="90"/>
<StackPanel Orientation="Vertical">
<TextBlock x:Name="tb1" VerticalAlignment="Top" HorizontalAlignment="Left" Foreground="Black" Width="Auto" Margin="27,20,0,0" FontWeight="SemiBold" FontFamily="Georgia" FontSize="22" Tap="tbUserName_Tap"/>
<TextBlock x:Name="tb2" VerticalAlignment="Top" Foreground="#FF747171" HorizontalAlignment="Left" Margin="27,10,0,0" FontFamily="Georgia" FontSize="20" Tap="tbScreenName_Tap"/>
</StackPanel>
</StackPanel>
<toolkit:ExpanderView x:Name="evMoreDetails" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,10,0,0" Collapsed="evMoreDetails_Collapsed" Header="V " Foreground="Black" FontSize="26" Expanded="evMoreDetails_Expanded">
<toolkit:ExpanderView.Items>
<StackPanel Orientation="Vertical" VerticalAlignment="Top">
<TextBlock Width="Auto" x:Name="Name" VerticalAlignment="Top" FontFamily="Segoe UI" TextWrapping="Wrap" Margin="10,8,0,0" FontSize="22" FontWeight="SemiBold" Foreground="Black" Text="{Binding name}" />
<TextBlock Width="Auto" x:Name="Name1" VerticalAlignment="Top" Margin="8,2,0,0" FontFamily="Segoe UI" TextWrapping="Wrap" FontSize="20" Foreground="Black" Text="{Binding name1}" />
</StackPanel>
</toolkit:ExpanderView.Items>
</toolkit:ExpanderView>
</StackPanel>
<StackPanel Grid.Row="6" Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top">
<toolkit:ExpanderView x:Name="evMore" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,20,0,50" Visibility="Collapsed">
<toolkit:ExpanderView.HeaderTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Left" >
<TextBlock Text="+ more" FontSize="26" Foreground="Black">
</TextBlock>
</Grid>
</DataTemplate>
</toolkit:ExpanderView.HeaderTemplate>
<toolkit:ExpanderView.Items>
<ListBox x:Name="lb" Height="250" HorizontalAlignment="Left">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Left" Width="{Binding Width}">
<Image x:Name="ProfilePic" Width="80" Height="80" Source="{Binding image}" VerticalAlignment="Top" Margin="0,10,0,0" />
<StackPanel Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Left" Width="{Binding Width}">
<StackPanel Orientation="Vertical" VerticalAlignment="Top">
<TextBlock Width="Auto" x:Name="Name" VerticalAlignment="Top" FontFamily="Segoe UI" TextWrapping="Wrap" Margin="10,8,0,0" FontSize="22" FontWeight="SemiBold" Foreground="Black" Text="{Binding name}" />
<TextBlock Width="Auto" x:Name="Name1" VerticalAlignment="Top" Margin="8,2,0,0" FontFamily="Segoe UI" TextWrapping="Wrap" FontSize="20" Foreground="Black" Text="{Binding name1}" />
</StackPanel>
</StackPanel>
<StackPanel Orientation="Vertical" VerticalAlignment="Top">
<CheckBox x:Name="chkSelect" IsChecked="{Binding isprim}" Foreground="Black" Tag="{Binding id}" HorizontalAlignment="Right" BorderBrush="Black" BorderThickness="0.5" Margin="0,0,0,0" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</toolkit:ExpanderView.Items>
</toolkit:ExpanderView>
</StackPanel>
</Grid>
I also have same problem in past. Please specify some height for expander item, in your case give some height to stackpanel at row 0.

scrollviewer doesnt scroll to bottom

It would be great if someone could help me. I currently have a phone page and I would like to display the images, but somehow my scrollviewer doesnt scroll to the bottom I can only see two rows of Images and after that the scrollviewer doesn't go any further.
Here is my XAML:
<ScrollViewer x:Name="Details">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Rectangle Fill="Black" Opacity="0.5" Grid.ColumnSpan="2" Grid.RowSpan="8"/>
<StackPanel Margin="15,10,1,0" Grid.Column="0" Grid.Row="0">
<TextBlock Text="{Binding xxx.Address}" Foreground="White" FontSize="22" FontWeight="Bold" />
<TextBlock Foreground="White">
<Run Text="{Binding xxx.Zipcode}" />
<Run />
<Run Text="{Binding xxx.Location}" />
</TextBlock>
</StackPanel>
<Image Source="/Assets/xxx.png" Height="50" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,15,0,0" />
<StackPanel Grid.Row="2">
<TextBlock Text="{Binding xxxx.xxx}" Foreground="White" MinHeight="50" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Left" FontWeight="Bold" Margin="15,10,1,0" FontSize="22" />
<TextBlock Text="xxxx" Foreground="White" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="15,0,1,10" />
</StackPanel>
<Image Source="/Assets/xxx.png" Grid.Row="2" Grid.Column="1" Height="50" Margin="10" />
<TextBlock Text="xxx:" Margin="15,10,1,0" Foreground="#FFD8051E" Grid.Column="0" Grid.Row="3"/>
<TextBlock Text="xxxx:" Margin="15,10,1,0" Grid.Column="0" Grid.Row="4" />
<TextBlock Margin="15,10,1,0" Grid.Column="1" Grid.Row="4" >
<Run Text="{Binding xxx}" />
<Run Text=" m" />
</TextBlock>
<TextBlock Text="xxxx:" Margin="15,10,1,0" Grid.Column="0" Grid.Row="5" />
<TextBlock Text="{Binding xxxx}" Margin="15,10,1,0" Grid.Column="1" Grid.Row="5" />
<TextBlock Text="xxxx:" Margin="15,10,1,0" Grid.Column="0" Grid.Row="6" />
<ItemsControl Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="7" ItemsSource="{Binding xxxx}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<tool:WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Margin="10" Source="{Binding .,Converter={StaticResource xxxxx}}" Height="100" Width="100" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</ScrollViewer>
I think the problem is in your ScrollViewer Properties.
there should be some more definition
<ScrollViewer Grid.Row="1"
Name="Details"
VerticalScrollBarVisibility="Visible" AllowDrop="False" ManipulationMode="Control">

Scrollviewer is not working

I am not able to make the scrollviewer working! The list is not scrollable. Maybe you can help me :)
<Grid x:Name="grid">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ScrollViewer Margin="0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<StackPanel VerticalAlignment="Top">
<ListBox x:Name="KommentareListView" ItemsSource="{Binding}" Foreground="White" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="0,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Background="#FF0083FF" Width="10" />
<StackPanel Margin="10,5,10,5" Grid.Column="1">
<TextBlock Text="{Binding Kommentar}"
FontSize="16" Margin="0,0,0,0" TextWrapping="Wrap" Foreground="Black"/>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Author}"
FontSize="12" Margin="0,0,0,0" Foreground="Black"/>
<TextBlock Text="{Binding Date}"
FontSize="12" Margin="30,0,0,0" Foreground="Black"/>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button x:Name="mehrKommentareLaden" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,10,0,0" Height="45" Visibility="Collapsed" Content="mehr Kommentare laden" Click="mehrKommentareLaden_Click" />
</StackPanel>
</ScrollViewer>
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Bottom" Grid.Row="1">
<StackPanel x:Name="AnmeldenPanel" VerticalAlignment="Bottom" Width="456" Visibility="Collapsed">
<Button x:Name="AnmeldenButton" Content="Anmelden" VerticalAlignment="Center" BorderBrush="Black" Foreground="Black" Margin="0" Click="AnmeldenButton_Click"/>
<TextBlock TextWrapping="Wrap" Text="Du musst dich anmelden, um Kommentare zu verfassen." Margin="15,0,0,0"/>
</StackPanel>
<toolkit:PhoneTextBox x:Name="KommentarBox" Hint="Dein Kommentar..." LengthIndicatorVisible="True" LengthIndicatorThreshold="10" DisplayedMaxLength="240" TextWrapping="Wrap" Background="#BFB2B2B2" BorderBrush="#BFFFFFFF" Foreground="#91000000" SelectionBackground="#FF0083FF" SelectionForeground="White" Style="{StaticResource PhoneTextBoxWhiteBackground}" Height="74" Width="456"/>
</StackPanel>
<!--<Controls:WatermarkTextBox x:Name="KommentarTextBox" Margin="0,0,100,20" TextWrapping="Wrap" Watermark="Dein Kommentar...." Height="30" VerticalAlignment="Center" FontFamily="Calibri" FontSize="17.333" BorderBrush="#CC000000"/>-->
</Grid>
Try making the List height to auto and everything else to auto which is in between List and ScrollView like you are having StackPanel.

Memory leak due to GridView in Windows Store apps

I have the following GridView
<GridView
x:Name="itemGridView"
AutomationProperties.AutomationId="ItemsGridView"
AutomationProperties.Name="Items"
TabIndex="1"
Grid.RowSpan="2"
Padding="116,136,116,46"
SelectionMode="Single"
IsSwipeEnabled="false"
Visibility="Collapsed">
<GridView.ItemTemplate>
<DataTemplate>
<!--<Border BorderBrush="DarkSeaGreen" BorderThickness="1">-->
<Grid Background="{Binding objBackgroundColor}" Opacity="1" Width="400" Height="80">
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="{Binding objCustomTestPaper.Name}" TextWrapping="Wrap" FontWeight="SemiBold" VerticalAlignment="Top" Foreground="{Binding objForegroundColor}" Style="{StaticResource TitleTextStyle}" FontSize="20" MaxHeight="25" Margin="10,5,10,0" />
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="120"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--<Image Grid.Column="0" Height="35" VerticalAlignment="Center" HorizontalAlignment="Center" Source="Assets/paper.png"></Image>-->
<StackPanel Grid.Column="0" Margin="5,7,0,0">
<callisto:Rating FontStretch="SemiCondensed" ItemCount="5" Value="{Binding objCustomTestPaper.TestRating}" FontWeight="Light" VerticalAlignment="Bottom" Margin="0,2,5,1" Background="Transparent" HorizontalAlignment="Left" Foreground="{Binding objForegroundColor}" IsHitTestVisible="False" FontSize="12" >
</callisto:Rating>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Text="Attempted by others:" Margin="4,0,0,0" FontSize="12" FontWeight="Light" Foreground="{Binding objForegroundColor}"></TextBlock>
<TextBlock Text="{Binding objCustomTestPaper.AttemptCount}" FontWeight="SemiBold" Margin="5,0,0,0" FontSize="12" Foreground="{Binding objForegroundColor}"></TextBlock>
<TextBlock Text="times" Margin="3,0,0,0" FontSize="12" FontWeight="Light" Foreground="{Binding objForegroundColor}"></TextBlock>
</StackPanel>
</StackPanel>
<StackPanel VerticalAlignment="Stretch" Grid.Column="2" Margin="0,0,0,0" >
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
<TextBlock Text="Time:" FontSize="16" Foreground="{Binding objForegroundColor}" VerticalAlignment="Bottom" FontWeight="SemiLight"></TextBlock>
<TextBlock Text="{Binding strTestDuration}" Margin="5,0,0,0" FontSize="18" VerticalAlignment="Bottom" Foreground="{Binding objForegroundColor}" FontWeight="SemiLight"></TextBlock>
</StackPanel>
<StackPanel Margin="0,2,0,0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
<TextBlock Text="Points:" FontSize="16" Margin="0,0,0,0" VerticalAlignment="Bottom" Foreground="{Binding objForegroundColor}" FontWeight="SemiLight"></TextBlock>
<TextBlock Text="{Binding objCustomTestPaper.TotalMarks}" Margin="5,0,0,0" VerticalAlignment="Bottom" FontSize="18" Foreground="{Binding objForegroundColor}" FontWeight="SemiLight"></TextBlock>
</StackPanel>
</StackPanel>
</Grid>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
It is working fine and loads data successfully but When I press back button the data remains in the memory (not usable) and keeps on increasing at various visits to the page. I don't know how how to clear the items of the GridView when OnNavigationFrom(,) method is called. I am trying to use objGridView.Items.Clear() but it throws some HRXXXX exception.