可能看起来很傻。当命令绑定时,无法确定此处的按钮示例代码,
我有自定义控件,
public class Stepper: ListBox
{
/// <summary>
/// Internal command used by the XAML template (public to be available in the XAML template). Not intended for external usage.
/// </summary>
public static readonly RoutedCommand BackCommand = new RoutedCommand();
static Stepper()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(UXStepper), new FrameworkPropertyMetadata(typeof(Stepper)));
}
public UXStepper()
{
CommandBindings.Add(new CommandBinding(BackCommand, (o, e) => ZoomFit(), (o, e) => e.CanExecute = true));
}
private void ZoomFit()
{
//some implementation
}
}
XAML代码
<Button HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="Back"
Command="{x:Static shui:Stepper.BackCommand}"/>
答案 0 :(得分:0)
如果我理解正确:您的问题是绑定无效
<Window.Resources>
<shui:Stepper x:Key="stepper"/>
</Window.Resources>
<Button HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="Back"
Command="{BackCommand, Source={StaticResource stepper}}"/>
<Button HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="Back"
Command="{BackCommand, Source={x:Static shui:Stepper.Instance}}"/>