Xaml Caliburn Micro Win8.1应用程序-未找到方法X的目标

Xaml Caliburn Micro Win8.1应用程序-未找到方法X的目标,xaml,mvvm,winrt-xaml,windows-8.1,caliburn.micro,Xaml,Mvvm,Winrt Xaml,Windows 8.1,Caliburn.micro,我是一个xaml新手,对WPF/商店应用程序还很陌生。我试图为Windows8.1商店应用程序创建一个简单的Caliburn Micro示例(根据最新代码编译)。但我无法让它运行,因为从昨天起我就遇到了错误-我确实尝试了我下载的源代码下的示例,它们运行得很好。和我试图从头开始创建的一样,它抛出了前面提到的异常。 这是整个解决方案的代码,如果配置/使用错误,请更正 CalMicSample\App.xaml: <caliburn:CaliburnApplication x:Class

我是一个xaml新手,对WPF/商店应用程序还很陌生。我试图为Windows8.1商店应用程序创建一个简单的Caliburn Micro示例(根据最新代码编译)。但我无法让它运行,因为从昨天起我就遇到了错误-我确实尝试了我下载的源代码下的示例,它们运行得很好。和我试图从头开始创建的一样,它抛出了前面提到的异常。 这是整个解决方案的代码,如果配置/使用错误,请更正

CalMicSample\App.xaml:

<caliburn:CaliburnApplication
    x:Class="CalMicSample.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:caliburn="using:Caliburn.Micro"
    RequestedTheme="Light">

</caliburn:CaliburnApplication>
CalMicSample\ViewModels\MyTestViewModel.cs

using Caliburn.Micro;
using CalMicSample.Helpers;
using CalMicSample.Models;
using System;

namespace CalMicSample.ViewModels
{
    public class MyTestViewModel : ViewModelBase
    {
        private string food;
        private MonkeyMood mood;


        public MyTestViewModel(INavigationService navigationService)
            : base(navigationService)
        {

        }

        public string Food 
        { 
            get 
            { 
                return food; 
            } 
            set 
            { 
                this.Set(ref food, value);
            } 
        }
        public MonkeyMood Mood 
        { 
            get 
            {
                return mood;
            } 
            set 
            { 
                this.Set(ref mood, value);
            }
        }

        public void FeedMonkey(string monkeyFood)
        {
            if (string.Compare(Food, "banana", StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                Mood = new MonkeyMood();
                Mood.Message = "Monkey is happy!";
                Mood.ImagePath = @"D:\Tryouts\CaliburnMicroSample\CalMicSample\CalMicSample\Assets\monkey-happy.jpg";
            }
            else
            {
                Mood = new MonkeyMood();
                Mood.Message = "Monkey is unhappy";
                Mood.ImagePath = @"D:\Tryouts\CaliburnMicroSample\CalMicSample\CalMicSample\Assets\monkeysad.jpg";
            }
        }

        public bool CanFeedMonkey(string monkeyFood)
        {
            return !string.IsNullOrWhiteSpace(monkeyFood);
        }
    }
}
CalMicSample\ViewModels\ViewModelBase.cs

using Caliburn.Micro;

namespace CalMicSample.ViewModels
{
    public abstract class ViewModelBase : Screen
    {
        private readonly INavigationService navigationService;

        protected ViewModelBase(INavigationService navigationService)
        {
            this.navigationService = navigationService;
        }

        public void GoBack()
        {
            navigationService.GoBack();
        }

        public bool CanGoBack
        {
            get
            {
                return navigationService.CanGoBack;
            }
        }
    }
}
CalMicSample\Views\MyTestView.xaml

<Page
    x:Class="CalMicSample.Views.MyTestView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CalMicSample.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:caliburn="using:Caliburn.Micro"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="171*"/>
            <RowDefinition Height="86*"/>
            <RowDefinition Height="382*"/>
            <RowDefinition Height="129*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="172*"/>
            <ColumnDefinition Width="328*"/>
            <ColumnDefinition Width="183*"/>
        </Grid.ColumnDefinitions>
        <Button x:Name="FeedMonkey" Content="Feed" caliburn:Message.Attach="FeedMonkey" Grid.Column="2" HorizontalAlignment="Left" Height="72" Margin="7,7,0,0" Grid.Row="1" VerticalAlignment="Top" Width="138" FontSize="36"/>
        <TextBox x:Name="txtFood" Grid.Column="1" HorizontalAlignment="Left" Height="66" Margin="10,10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Banana" VerticalAlignment="Top" Width="636" FontSize="36"/>
        <TextBlock x:Name="lblFeedMonkey" Grid.Column="1" HorizontalAlignment="Left" Margin="10,119,0,5" TextWrapping="Wrap" Text="Give some food to the monkey" Width="636" FontSize="36" FontWeight="Bold"/>
        <TextBlock x:Name="lblMonkeyMood" Grid.Column="1" HorizontalAlignment="Center" Margin="59,25,37,10" Grid.Row="3" TextWrapping="Wrap" VerticalAlignment="Center" Height="94" Width="560" FontSize="72"/>
        <Image x:Name="imgMonkey" Grid.Column="1" HorizontalAlignment="Left" Height="362" Margin="10,10,0,0" Grid.Row="2" VerticalAlignment="Top" Width="636"/>

    </Grid>
</Page>

CalMicSample\Views\MyTestView.xaml.cs

using Windows.UI.Xaml.Controls;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace CalMicSample.Views
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MyTestView : Page
    {
        public MyTestView()
        {
            this.InitializeComponent();
        }
    }
}
使用Windows.UI.Xaml.Controls;
//空白页项模板被记录在http://go.microsoft.com/fwlink/?LinkId=234238
名称空间CalMicSample.Views
{
/// 
///可以单独使用或在框架内导航到的空页。
/// 
公共密封部分类MyTestView:第页
{
公共MyTestView()
{
this.InitializeComponent();
}
}
}

虚拟机中的feedmonkey方法需要一个字符串参数,但在连接到按钮时没有提供。请参见此处了解更多信息:

Rob是正确的,您需要匹配您的
FeedMonkey(字符串monkeyFood)
,目前“Caliburn.Micro”无法找到正确的方法

您可能希望使用以下内容:

// You wouldn't want to use a hard coded string, but this is how you'd do it.
caliburn:Message.Attach="FeedMonkey('banana')" 

// Or you can pass some of the special values linked in Rob's answer (the Caliburn docs).
// You'd probably want a sub property, depending on what it was you were passing. 
caliburn:Message.Attach="FeedMonkey($dataContext)"

谢谢你,罗布。我怎么没注意到!:)
<Page
    x:Class="CalMicSample.Views.MyTestView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CalMicSample.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:caliburn="using:Caliburn.Micro"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="171*"/>
            <RowDefinition Height="86*"/>
            <RowDefinition Height="382*"/>
            <RowDefinition Height="129*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="172*"/>
            <ColumnDefinition Width="328*"/>
            <ColumnDefinition Width="183*"/>
        </Grid.ColumnDefinitions>
        <Button x:Name="FeedMonkey" Content="Feed" caliburn:Message.Attach="FeedMonkey" Grid.Column="2" HorizontalAlignment="Left" Height="72" Margin="7,7,0,0" Grid.Row="1" VerticalAlignment="Top" Width="138" FontSize="36"/>
        <TextBox x:Name="txtFood" Grid.Column="1" HorizontalAlignment="Left" Height="66" Margin="10,10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Banana" VerticalAlignment="Top" Width="636" FontSize="36"/>
        <TextBlock x:Name="lblFeedMonkey" Grid.Column="1" HorizontalAlignment="Left" Margin="10,119,0,5" TextWrapping="Wrap" Text="Give some food to the monkey" Width="636" FontSize="36" FontWeight="Bold"/>
        <TextBlock x:Name="lblMonkeyMood" Grid.Column="1" HorizontalAlignment="Center" Margin="59,25,37,10" Grid.Row="3" TextWrapping="Wrap" VerticalAlignment="Center" Height="94" Width="560" FontSize="72"/>
        <Image x:Name="imgMonkey" Grid.Column="1" HorizontalAlignment="Left" Height="362" Margin="10,10,0,0" Grid.Row="2" VerticalAlignment="Top" Width="636"/>

    </Grid>
</Page>
using Windows.UI.Xaml.Controls;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace CalMicSample.Views
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MyTestView : Page
    {
        public MyTestView()
        {
            this.InitializeComponent();
        }
    }
}
// You wouldn't want to use a hard coded string, but this is how you'd do it.
caliburn:Message.Attach="FeedMonkey('banana')" 

// Or you can pass some of the special values linked in Rob's answer (the Caliburn docs).
// You'd probably want a sub property, depending on what it was you were passing. 
caliburn:Message.Attach="FeedMonkey($dataContext)"