我在 xaml 块中创建了一个RoutedUICommand
,如下所示,但无论我输入的是x:name
值,它都会抛出:
无法在此范围内注册重复名称“_Roots”。
我是WPF的新手,但不是.net ......这看起来很奇怪......我错过了什么......提前谢谢。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ImagingLibrary;
using System.Drawing;
using System.IO;
namespace TranshelperWpf
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void RootsCommandBinding_Executed(object sender,
ExecutedRoutedEventArgs e)
{
}
private void RootsCommandBinding_CanExecute(object sender,
CanExecuteRoutedEventArgs e)
{
}
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
}
private void UsageCommandBinding_CanExecute(object sender,
CanExecuteRoutedEventArgs e)
{
}
private void UsageCommandBinding_Executed(object sender,
ExecutedRoutedEventArgs e)
{
}
}
public class RootModel
{
public int ID { get; set; }
public Byte[] Root { get; set; }
public string DescriptiveName { get; set; }
public string Definition { get; set; }
public int Length { get; set; }
public string ContentType { get; set; }
public string WpfPath { get; set; }
}
}
- xaml标记
<Window x:Class="TranshelperWpf.MainWindow"
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:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:TranshelperWpf"
mc:Ignorable="d"
Title="Trans-Help" Height="350" Width="525" Background="{DynamicResource WindowBackgroundBrush}">
<Window.Resources>
<LinearGradientBrush x:Key="WindowBackgroundBrush">
<GradientStop Offset="0" Color="Silver"/>
<GradientStop Offset="1" Color="Gray"/>
</LinearGradientBrush>
<RoutedUICommand x:Key="Roots" x:Name="_Roots" />
<RoutedUICommand x:Key="Usage" x:Name="_Usage" />
</Window.Resources>
<Window.CommandBindings>
<CommandBinding Command="{StaticResource Roots}"
CanExecute="RootsCommandBinding_CanExecute"
Executed="RootsCommandBinding_Executed" />
<CommandBinding Command="{StaticResource Usage}"
CanExecute="UsageCommandBinding_CanExecute"
Executed="UsageCommandBinding_Executed" />
</Window.CommandBindings>
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_Admin">
<MenuItem Header="_Roots" Command="{StaticResource Roots}" />
<MenuItem Header="_Usage"/>
<MenuItem Header="_Prefixes Suffixes" />
<MenuItem Header="_Rules"/>
</MenuItem>
</Menu>
</DockPanel>
</Window>