단추를 명령에 연결 한 다음 Command.Execute()를 사용하여 Code의 아무 곳이나 명령을 트리거 할 수 있습니다. 사이비 코드 :
XAML :
<UserControl x:Class="ClassName"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:commands="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation">
<Button commands:Click.Command="{Binding MyCommand}" />
</UserControl>
CODE (또는 MVVM 뒤) :이 MVVM 세계에서 특히 잘 작동
public class ClassName
{
///Class constructor
public ClassName()
{ /// implement the command behaviour as a delegate
MyCommand = new DelegateCommand<object>(
delegate{
/// do your OnClick() behaviour implementation here
}
);
}
private DelegateCommand<object> _myCommand;
public DelegateCommand<object> MyCommand
{
get { return _myCommand; }
set { myCommand=value;
OnPropertyChanged("MyCommand");}
}
/// Another method called from somewhere else in code
void SomeOtherMethod()
{
MyCommand.Execute(null);
}
}
.
이 문제는 아직 SL4에 있습니다 (SL5가 의심됩니다). 앞에서 설명한 브라우저 솔루션 외에도 브라우저 솔루션을 포함하도록 답변을 업데이트했습니다. –