cazino86
یک شنبه 14 شهریور 1389, 19:13 عصر
سلام...
من از کلاس زیر در برنامه خودم استفاده کردم و یک کامند رو در اون معرفی کردم :
public class DataCommands
{
private static RoutedUICommand saveall;
static DataCommands()
{
// Initialize the command.
InputGestureCollection inputs = new InputGestureCollection();
inputs.Add(new KeyGesture(Key.S, ModifierKeys.Shift, "Shift+R"));
saveall = new RoutedUICommand(
"SaveAll", "SaveAll", typeof(DataCommands), inputs);
}
public static RoutedUICommand SaveAll
{
get { return saveall; }
}
}
کلاسم رو به رفرنس ها اظافه کردم :
xmlns:CustomCommand="clr-namespace:Editor.Classes"
و به این صورت اون رو مورد استفاده قرار دادم :
<CommandBinding Command="CustomCommand:DataCommands.SaveAll" x:Name="SaveAllCommand" Executed="SaveAllCommand_Executed" ></CommandBinding>
<MenuItem Header="Save All" Name="SaveAll_MenuItem" Command="CustomCommand:DataCommands.SaveAll" Click="SaveAll_MenuItem_Click"></MenuItem>
اما ارور زیر رو گرفتم :
Error 5 Value 'CustomCommand:DataCommands.SaveAll' cannot be assigned to property 'Command'. Exception has been thrown by the target of an invocation. C:\Documents and Settings\amir\My Documents\Visual Studio 2008\Projects\Editor\Editor\Window1.xaml 22 25
اگه به جای شیفت از الت یا کنترل استفاده کنم مشکل حل میشه . اما چرا نمیتونم از شیفت استفاده کنم ؟
من از کلاس زیر در برنامه خودم استفاده کردم و یک کامند رو در اون معرفی کردم :
public class DataCommands
{
private static RoutedUICommand saveall;
static DataCommands()
{
// Initialize the command.
InputGestureCollection inputs = new InputGestureCollection();
inputs.Add(new KeyGesture(Key.S, ModifierKeys.Shift, "Shift+R"));
saveall = new RoutedUICommand(
"SaveAll", "SaveAll", typeof(DataCommands), inputs);
}
public static RoutedUICommand SaveAll
{
get { return saveall; }
}
}
کلاسم رو به رفرنس ها اظافه کردم :
xmlns:CustomCommand="clr-namespace:Editor.Classes"
و به این صورت اون رو مورد استفاده قرار دادم :
<CommandBinding Command="CustomCommand:DataCommands.SaveAll" x:Name="SaveAllCommand" Executed="SaveAllCommand_Executed" ></CommandBinding>
<MenuItem Header="Save All" Name="SaveAll_MenuItem" Command="CustomCommand:DataCommands.SaveAll" Click="SaveAll_MenuItem_Click"></MenuItem>
اما ارور زیر رو گرفتم :
Error 5 Value 'CustomCommand:DataCommands.SaveAll' cannot be assigned to property 'Command'. Exception has been thrown by the target of an invocation. C:\Documents and Settings\amir\My Documents\Visual Studio 2008\Projects\Editor\Editor\Window1.xaml 22 25
اگه به جای شیفت از الت یا کنترل استفاده کنم مشکل حل میشه . اما چرا نمیتونم از شیفت استفاده کنم ؟