好的,這裏是最終的溶劑。
XAML:
<Grid xmlns:dm="clr-namespace:MyNameSpace;assembly=MyAssembly">
<Grid.Resources>
<dm:TimeSource x:Key="timesource1"/>
</Grid.Resources>
<Button Command="{x:Static dm:TimeSource.Update}"
CommandParameter="any_parameter"
CommandTarget="{Binding Source={StaticResource timesource1}}">Update time</Button>
</Grid>
CODE在TIMESOURCE類:
public class TimeSource : System.Windows.UIElement {
public static RoutedCommand Update = new RoutedCommand();
private void UpdateExecuted(object sender, ExecutedRoutedEventArgs e)
{
// code
}
private void UpdateCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
// Constructor
public TimeSource() {
CommandBinding cb = new CommandBinding(TimeSource.Update, UpdateExecuted, UpdateCanExecute);
CommandBindings.Add(cb2);
}
}
TIMESOURCE已經以自UIElement爲了具有化CommandBindings導出。但結果是直接從XAML調用外部裝配方法。通過點擊按鈕,對象timesource1的'UpdateExecuted'方法被調用,這正是我正在尋找的。
來源
2010-10-20 08:34:55
Gal
這表明我非常好的方向。感謝您的幫助,並查看我的最終溶劑。 – Gal 2010-10-20 08:36:05