【发布时间】:2015-03-20 05:25:09
【问题描述】:
我在绑定位于我的 Windows Phone 应用程序侧边栏中的按钮时遇到问题。按钮绑定似乎消失了..
这是我现在的代码
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<sidebar:SidebarControl x:Name="sidebarControl"
HeaderText="WP"
HeaderBackground="YellowGreen"
HeaderForeground="White"
SidebarBackground="{StaticResource PhoneChromeBrush}">
<sidebar:SidebarControl.SidebarContent>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="380">
<Button Content="Go to page 2" x:Name="GoToPage2"/>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
</Grid>
</sidebar:SidebarControl.SidebarContent>
<Grid VerticalAlignment="Top" HorizontalAlignment="Stretch"
Margin="12">
<TextBlock Style="{StaticResource PhoneTextNormalStyle}">Your current view goes here</TextBlock>
</Grid>
</sidebar:SidebarControl>
</Grid>
</Grid>
目前我正在为侧边栏使用一个名为 SidebarWP8 的 nuget。也许 Calinbrun.Micro 不适用于这个?还是我必须在网格中插入与 VM 的绑定?
ViewModel 中的方法如下:
private readonly INavigationService navigationService;
public MainPageViewModel(INavigationService navigationService)
{
this.navigationService = navigationService;
}
public void GoToPage2()
{
navigationService.UriFor<Page2ViewModel>().Navigate();
}
【问题讨论】:
-
究竟是什么在那里不起作用?您的按钮没有分配点击处理程序,只是一个名称。您必须添加 Click="..." 或命令。
-
根据 Caliburn.Micro 的文档,如果 x:="exampleName" 与方法名相同,它应该可以工作吗?该按钮在侧边栏范围之外工作,但当它在范围内时,绑定不再工作。它不调用该方法。无论如何感谢您的回答:)
标签: c# windows-phone-8 mvvm caliburn.micro