2014-10-23 2 views
1

다른 클래스가 속성으로 설정된보기 모델이 있습니다. 다른 클래스에는 ICommand의 속성이 구현되어 있습니다. 더블 클릭으로 명령 중 하나를 실행하고 싶습니다.Message.Attach를 사용하여 다른 개체의 메서드를 호출하는 방법

불행히도 Caliburn.Micro는 예외를 발생시킵니다 ("Commands.Command.Execute 메서드에 대한 대상이 없습니다").

나는 그물을 검색하고 문서를 읽으려고했지만 아무런 성공도하지 못했습니다.

올바르게 수행하는 방법은 무엇입니까?

참고 : 실제 응용 프로그램에서는 메시지가 명령 클래스가 포함 된보기 모델과 다른 DataContext가있는 격자보기에 첨부 될 수 있습니다.

XAML :

<Window x:Class="WpfApplication8.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:cal="http://www.caliburnproject.org"> 
    <Grid> 
     <TextBox 
      cal:Message.Attach="[Event MouseDoubleClick] 
       = [Action Commands.Command.Execute(null)]" /> 
    </Grid> 
</Window> 

코드 숨김 클래스 : @alik 주석, 완벽한 솔루션으로

namespace WpfApplication8 
{ 
    public partial class MainWindow 
    { 
     public Commands Commands { get; set; } 

     public MainWindow() 
     { 
      this.Commands = 
       new Commands { Command = new Command { MainWindow = this } }; 

      this.InitializeComponent(); 

      this.DataContext = this; 
     } 
    } 

    public class Commands 
    { 
     public Command Command { get; set; } 
    } 

    public class Command 
    { 
     public MainWindow MainWindow { get; set; } 

     public void Execute(object parameter) 
     { 
      this.MainWindow.Title = "Executed"; 
     } 
    } 
} 
+1

체크 아웃 고려 [Action.TargetWithoutContext] (https://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions) –

+1

감사합니다. cal : Message.Attach = "[이벤트 MouseDoubleClick] = [동작 실행 (null)]" cal : Action.TargetWithoutContext = "{바인딩 명령. 명령}" – alik

답변

0

은 다음과 같습니다

<Window x:Class="WpfApplication8.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:cal="http://www.caliburnproject.org"> 
    <Grid> 
     <TextBox 
      cal:Message.Attach="[Event MouseDoubleClick] = [Action Execute(null)]" 
      cal:Action.TargetWithoutContext="{Binding Commands.Command}"/> 
    </Grid> 
</Window> 
관련 문제