Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding when navigating with caliburn AppBarButton not working
    text
    copied!<p>I have this strange problem with AppBarButton. I have binded the button to a method in my view model like this:</p> <p>XAML for MainView</p> <pre><code>&lt;phone:PhoneApplicationPage.ApplicationBar&gt; &lt;shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" BackgroundColor="{StaticResource HsAppBarColor}" Opacity="1"&gt; &lt;shell:ApplicationBar.Buttons&gt; &lt;cal:AppBarButton IconUri="/icons/appbar.feature.settings.rest.png" Text="ajustes" Message="GoToSettings" /&gt; &lt;cal:AppBarButton IconUri="/icons/appbar.favs.rest.png" Text="favoritos" Message="GoToFavs" /&gt; &lt;/shell:ApplicationBar.Buttons&gt; &lt;/shell:ApplicationBar&gt; &lt;/phone:PhoneApplicationPage.ApplicationBar&gt; </code></pre> <p>C# for MainViewModel</p> <pre><code> public void GoToSettings() { navigation.UriFor&lt;SettingsViewModel&gt;().Navigate(); } </code></pre> <p>It fires GoToSettings code and it navigates to SettingsView page however, SettingsViewModel is never initialized and the constructor is not called. Caliburn code for binding view with view model doesn't work.</p> <p>I wonder if having a Pivot in MainPage which sets a DataContext for its Sample Data could affect. I tried commenting the data context but it still didn't called SettingsViewModel constructor.</p> <p>This is the Pivot XAML code</p> <pre><code>&lt;controls:Pivot toolkit:TurnstileFeatherEffect.FeatheringIndex="0" Margin="0" Title="" DataContext="{Binding Source={StaticResource Stores}}" TitleTemplate="{StaticResource StoresPivotTitleTemplate}" HeaderTemplate="{StaticResource StoresPivotHeaderTemplate}" Style="{StaticResource StoresPivotStyle}" FontFamily="Arial Narrow" Background="{x:Null}"&gt; &lt;controls:PivotItem Header="Restorantes" BorderThickness="0,-20,0,0" Margin="12,0" Background="{x:Null}"&gt; &lt;Grid&gt; &lt;ListBox toolkit:TurnstileFeatherEffect.FeatheringIndex="2" cal:Message.Attach="[Event SelectionChanged] = [Action Restaurants_SelectionChanged];" ItemTemplate="{StaticResource StoresListItemTemplate}" ItemsSource="{Binding Collection}" Margin="0" ItemContainerStyle="{StaticResource StoresListContainerStyle}" Background="{x:Null}"/&gt; &lt;/Grid&gt; &lt;/controls:PivotItem&gt; &lt;controls:PivotItem Header="Tiendas" Margin="12,0"&gt; &lt;Grid&gt; &lt;ListBox toolkit:TurnstileFeatherEffect.FeatheringIndex="2" cal:Message.Attach="[Event SelectionChanged] = [Action Stores_SelectionChanged];" ItemTemplate="{StaticResource StoresListItemTemplate}" ItemsSource="{Binding Collection}" Margin="0" ItemContainerStyle="{StaticResource StoresListContainerStyle}" FontFamily="Segoe WP"/&gt; &lt;/Grid&gt; &lt;/controls:PivotItem&gt; &lt;/controls:Pivot&gt; </code></pre> <p>Stores_SelectionChanged method also navigates to a page but this time the binding works and the viewmodel constructor is fired.</p> <p>Any idea why it doesn't work in the AppBarButton but it does work in the Pivot attached action when they use the same view model behind?</p> <p>EDIT: added full xaml for view</p> <pre><code> &lt;phone:PhoneApplicationPage xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls" xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro" xmlns:controlsPrimitives="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone.Controls" xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" x:Class="Happyshop.Views.StoresView" SupportedOrientations="Portrait" Orientation="Portrait" mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" shell:SystemTray.IsVisible="True" Foreground="{x:Null}"&gt; &lt;toolkit:TransitionService.NavigationInTransition&gt; &lt;toolkit:NavigationInTransition&gt; &lt;toolkit:NavigationInTransition.Backward&gt; &lt;toolkit:TurnstileFeatherTransition Mode="BackwardIn"/&gt; &lt;/toolkit:NavigationInTransition.Backward&gt; &lt;toolkit:NavigationInTransition.Forward&gt; &lt;toolkit:TurnstileFeatherTransition Mode="ForwardIn" BeginTime="0:0:0.7"/&gt; &lt;/toolkit:NavigationInTransition.Forward&gt; &lt;/toolkit:NavigationInTransition&gt; &lt;/toolkit:TransitionService.NavigationInTransition&gt; &lt;toolkit:TransitionService.NavigationOutTransition&gt; &lt;toolkit:NavigationOutTransition&gt; &lt;toolkit:NavigationOutTransition.Backward&gt; &lt;toolkit:TurnstileFeatherTransition Mode="BackwardOut"/&gt; &lt;/toolkit:NavigationOutTransition.Backward&gt; &lt;toolkit:NavigationOutTransition.Forward&gt; &lt;toolkit:TurnstileFeatherTransition Mode="ForwardOut" BeginTime="0:0:0.2"/&gt; &lt;/toolkit:NavigationOutTransition.Forward&gt; &lt;/toolkit:NavigationOutTransition&gt; &lt;/toolkit:TransitionService.NavigationOutTransition&gt; &lt;phone:PhoneApplicationPage.Resources&gt; &lt;Style x:Key="StoresPivotStyle" TargetType="controls:Pivot"&gt; &lt;Setter Property="Margin" Value="0"/&gt; &lt;Setter Property="Padding" Value="0"/&gt; &lt;Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/&gt; &lt;Setter Property="Background" Value="Transparent"/&gt; &lt;Setter Property="ItemsPanel"&gt; &lt;Setter.Value&gt; &lt;ItemsPanelTemplate&gt; &lt;Grid/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="controls:Pivot"&gt; &lt;Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"&gt; &lt;Grid.Background&gt; &lt;SolidColorBrush Color="{StaticResource HsDarkBlue}"/&gt; &lt;/Grid.Background&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="65"/&gt; &lt;RowDefinition Height="96"/&gt; &lt;RowDefinition/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid CacheMode="BitmapCache" Grid.RowSpan="3"/&gt; &lt;Border Margin="-12,-5,0,0" BorderThickness="0,0,0,0"&gt; &lt;ContentPresenter ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" Margin="12,5,0,0"/&gt; &lt;/Border&gt; &lt;Border Grid.Row="1" toolkit:TurnstileFeatherEffect.FeatheringIndex="1" &gt; &lt;controlsPrimitives:PivotHeadersControl x:Name="HeadersListElement" Background="Black"/&gt; &lt;/Border&gt; &lt;ItemsPresenter x:Name="PivotItemPresenter" Margin="0" Grid.Row="2"/&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/phone:PhoneApplicationPage.Resources&gt; &lt;phone:PhoneApplicationPage.Background&gt; &lt;SolidColorBrush Color="{StaticResource HsDarkBlue}"/&gt; &lt;/phone:PhoneApplicationPage.Background&gt; &lt;phone:PhoneApplicationPage.FontFamily&gt; &lt;StaticResource ResourceKey="PhoneFontFamilyNormal"/&gt; &lt;/phone:PhoneApplicationPage.FontFamily&gt; &lt;phone:PhoneApplicationPage.FontSize&gt; &lt;StaticResource ResourceKey="PhoneFontSizeNormal"/&gt; &lt;/phone:PhoneApplicationPage.FontSize&gt; &lt;phone:PhoneApplicationPage.ApplicationBar&gt; &lt;shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" BackgroundColor="{StaticResource HsAppBarColor}" Opacity="1"&gt; &lt;shell:ApplicationBar.Buttons&gt; &lt;cal:AppBarButton IconUri="/icons/appbar.feature.settings.rest.png" Text="ajustes" Message="GoToSettings" /&gt; &lt;cal:AppBarButton IconUri="/icons/appbar.favs.rest.png" Text="favoritos" Message="GoToFavs" /&gt; &lt;/shell:ApplicationBar.Buttons&gt; &lt;/shell:ApplicationBar&gt; &lt;/phone:PhoneApplicationPage.ApplicationBar&gt; &lt;controls:Pivot toolkit:TurnstileFeatherEffect.FeatheringIndex="0" Margin="0" Title="" DataContext="{Binding Source={StaticResource Stores}}" TitleTemplate="{StaticResource StoresPivotTitleTemplate}" HeaderTemplate="{StaticResource StoresPivotHeaderTemplate}" Style="{StaticResource StoresPivotStyle}" FontFamily="Arial Narrow" Background="{x:Null}"&gt; &lt;controls:PivotItem Header="Restorantes" BorderThickness="0,-20,0,0" Margin="12,0" Background="{x:Null}"&gt; &lt;Grid&gt; &lt;ListBox toolkit:TurnstileFeatherEffect.FeatheringIndex="2" cal:Message.Attach="[Event SelectionChanged] = [Action Restaurants_SelectionChanged];" ItemTemplate="{StaticResource StoresListItemTemplate}" ItemsSource="{Binding Collection}" Margin="0" ItemContainerStyle="{StaticResource StoresListContainerStyle}" Background="{x:Null}"/&gt; &lt;/Grid&gt; &lt;/controls:PivotItem&gt; &lt;controls:PivotItem Header="Tiendas" Margin="12,0"&gt; &lt;Grid&gt; &lt;ListBox toolkit:TurnstileFeatherEffect.FeatheringIndex="2" cal:Message.Attach="[Event SelectionChanged] = [Action Stores_SelectionChanged];" ItemTemplate="{StaticResource StoresListItemTemplate}" ItemsSource="{Binding Collection}" Margin="0" ItemContainerStyle="{StaticResource StoresListContainerStyle}" FontFamily="Segoe WP"/&gt; &lt;/Grid&gt; &lt;/controls:PivotItem&gt; &lt;/controls:Pivot&gt; </code></pre> <p></p> <p>UPDATE It was a stupid error. When you use generate class with intellisense the class created is not marked as public. Classes are by default marked as internal so Caliburn project could not access the ViewModel and hence why it would not bind it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload