为什么赢了';tc#WPF RoutedCommands编译?

为什么赢了';tc#WPF RoutedCommands编译?,c#,C#,我的问题如下,上面的代码不会编译。我尝试过保存、清理和重建我的VisualStudio项目,但仍然没有成功。它表示命令转换器无法从system.string转换。显然,我要么误解了RoutedCommand,要么不能以这种方式将其用作自定义命令。有没有一种方法可以强制RoutedCommand创建新命令,或者有另一种方法可以使用自定义命令?您有几行输入错误,这很可能会导致“CommandConverter无法从System.String转换”错误,因为它无法识别该命令 更改此项: <Win

我的问题如下,上面的代码不会编译。我尝试过保存、清理和重建我的VisualStudio项目,但仍然没有成功。它表示命令转换器无法从system.string转换。显然,我要么误解了RoutedCommand,要么不能以这种方式将其用作自定义命令。有没有一种方法可以强制RoutedCommand创建新命令,或者有另一种方法可以使用自定义命令?

您有几行输入错误,这很可能会导致“CommandConverter无法从System.String转换”错误,因为它无法识别该命令

更改此项:

<Window x:Class="CostelloM_Data_Persistence_v1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="ContactMyPeeps(IllegalVersion)" Height="350" Width="525">
    <Window.Resources>
        <RoutedCommand x:Key="Saveas"/>
    </Window.Resources>
    <Window.CommandBindings> 
        <CommandBinding Command="Saveas" Executed="Save_As"/>
    </Window.CommandBindings>
    <Window.InputBindings>
        <KeyBinding Key="S"
                    Modifiers="Control + Shift"
                    Command="Saveas"/>
    </Window.InputBindings>
    <Grid>

        <StackPanel Orientation="Vertical">
        <Menu>
                <MenuItem Header="File">
                    <MenuItem Command="Save" Header="Save"/>
                    <MenuItem Command="Saveas" Header="Save as" InputGestureText="Ctrl+Shift+S"/>
                    <MenuItem Command="Open" Header="Open"/>
                </MenuItem>
            </Menu>
        <ItemsControl>
                <ComboBox>

                </ComboBox>
        </ItemsControl>
        </StackPanel>
    </Grid>
</Window>

对此:(大写“A”)


您正在资源中定义命令,因此需要告诉绑定系统它在资源中。您需要将XAML中的几个位置更改为

<CommandBinding Command="SaveAs" Executed="Save_As"/>
但是,在
ApplicationCommands
类中有几个预定义的标准命令,如Open、Save和SaveAs。绑定系统将自动尝试绑定到这些设备,但套管非常重要。这:

Command="{StaticResource Saveas}"
将绑定到
ApplicationCommand
中定义的相应命令。那么在参考资料中定义的命令就变得不必要了。

在这里回答
Command="{StaticResource Saveas}"
Command="SaveAs"