本文整理汇总了C#中GalaSoft.MvvmLight.Command.RelayCommand.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# RelayCommand.Execute方法的具体用法?C# RelayCommand.Execute怎么用?C# RelayCommand.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GalaSoft.MvvmLight.Command.RelayCommand
的用法示例。
在下文中一共展示了RelayCommand.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FeedSettingsViewModel
public FeedSettingsViewModel()
{
Title = "Feeds";
CoAppService = new LocalServiceLocator().CoAppService;
Add =
new RelayCommand<string>(
(feedUrl) =>
{
RaiseAllCanExecutesChanged(false);
CoAppService.AddSystemFeed(feedUrl).ContinueWith((t) => ReloadFeeds()).ContinueWith(
t => RaiseAllCanExecutesChanged(true));
});
Remove =
new RelayCommand<string>(
(feedUrl) =>
{
RaiseAllCanExecutesChanged(false);
CoAppService.RemoveSystemFeed(feedUrl).ContinueWith((t) => ReloadFeeds()).ContinueWith(
t =>
RaiseAllCanExecutesChanged(true));
});
//if can't elevate, do something
ElevateAdd = new RelayCommand<string>((s) => CoAppService.Elevate().ContinueAlways(t => ReloadPolicies()).ContinueWith((t) => Add.Execute(s)));
ElevateRemove = new RelayCommand<string>((s) => CoAppService.Elevate().ContinueWith(t => ReloadPolicies()).ContinueWith((t) => Remove.Execute(s)));
Loaded += ReloadFeeds;
}
示例2: ConfigViewModel
public ConfigViewModel()
{
Model = new Config() { PandocExePath = "pandoc.exe" };
DetectVersion = new RelayCommand(() =>
{
IsBusy = true;
Task.Factory.StartNew(() =>
{
DetectedVersion = PandocRunner.Version(this.GetLocator().Config.Model.PandocExePath);
}).ContinueWith(task =>
{
IsBusy = false;
});
}, () => !IsBusy);
Save = new RelayCommand(() =>
{
var repo = RepositoryFactory.GetInstance<Config>();
if (repo.Exists(Model.Key))
repo.Update(Model);
else repo.Add(Model);
});
Load = new RelayCommand(() =>
{
var repo = RepositoryFactory.GetInstance<Config>();
Model = repo.Any() ? repo.First() : Model;
});
this.PropertyChanged += (sender, e) => Save.Execute(null);
Load.Execute(null);
DetectVersion.Execute(null);
}
示例3: TestCallingExecuteWhenCanExecuteIsFalse
public void TestCallingExecuteWhenCanExecuteIsFalse()
{
var counter = 0;
var command = new RelayCommand(
() => counter++,
() => _canExecute);
command.Execute(null);
Assert.AreEqual(1, counter);
_canExecute = false;
command.Execute(null);
Assert.AreEqual(1, counter);
_canExecute = true;
command.Execute(null);
Assert.AreEqual(2, counter);
}
示例4: OrdersListingBaseViewModel
protected OrdersListingBaseViewModel()
{
SetupCommand = new RelayCommand(SetUp);
TabSelectionChangedCommand = new RelayCommand<SelectionChangedEventArgs>(TabSelectionChanged);
OrdersSummaryList = new ObservableCollection<OrderItemSummary>();
PaymentInfoList = new ObservableCollection<PaymentInfo>();
SalesmenList=new ObservableCollection<DistributorSalesman>();
ClearSearchTextCommand=new RelayCommand(ClearSearchText);
ExportToCsvCommand=new RelayCommand(ExportSelectedTabItem);
SetupCommand.Execute(null);
ContinueSelectedOrderCommand = new RelayCommand<OrderItemSummary>(ContinueSelectedOrder);
ListOrdersCommand = new RelayCommand(ListOrders);
}
示例5: MainViewModel
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// </summary>
public MainViewModel(IDataService dataService)
{
_dataService = dataService;
Users = new ObservableCollection<User>();
ReadAllUsersCommand = new RelayCommand(GetUsers);
//Execute ReadAllUsersCommand to display all users on the main window when the application launches
if (ReadAllUsersCommand.CanExecute(null))
ReadAllUsersCommand.Execute(null);
SearchUsersCommand = new RelayCommand(SearchUsers);
SendUserCommand = new RelayCommand(SendUser);
ReceiveRefreshUsersMessage();
}
示例6: UnshelveServiceModel
public UnshelveServiceModel(ITeamPilgrimServiceModelProvider teamPilgrimServiceModelProvider,
ITeamPilgrimVsService teamPilgrimVsService,
ProjectCollectionServiceModel projectCollectionServiceModel, WorkspaceServiceModel workspaceServiceModel)
: base(teamPilgrimServiceModelProvider, teamPilgrimVsService)
{
ProjectCollectionServiceModel = projectCollectionServiceModel;
WorkspaceServiceModel = workspaceServiceModel;
ShelvesetOwner = projectCollectionServiceModel.TfsTeamProjectCollection.AuthorizedIdentity.UniqueName;
FindShelvesetsCommand = new RelayCommand<string>(FindShelvesets, CanFindShelvesets);
CancelCommand = new RelayCommand(Cancel, CanCancel);
ViewPendingSetCommand = new RelayCommand<ShelvesetModel>(ViewPendingSet, CanViewPendingSet);
UnshelveCommand = new RelayCommand<ObservableCollection<object>>(Unshelve, CanUnshelve);
DeleteCommand = new RelayCommand<ObservableCollection<object>>(Delete, CanDelete);
DetailsCommand = new RelayCommand<ObservableCollection<object>>(Details, CanDetails);
FindShelvesetsCommand.Execute(null);
}
示例7: MainWindowViewModel
public MainWindowViewModel()
{
#region ChangeNumberOfCubesCommand
ChangeNumberOfCubesCommand = new RelayCommand<EventArgs>(e =>
{
Status = Strings.ChangingNumberStatus;
var args = e as RoutedPropertyChangedEventArgs<double>;
if (args != null)
{
var numToChange = Math.Abs(Convert.ToInt32(CubeViewModels.Count - args.NewValue));
if (args.NewValue < CubeViewModels.Count) // removing cubes
{
for (var i = 0; i < numToChange; i++)
{
CubeViewModels.RemoveAt(CubeViewModels.Count - 1);
}
NeighborCalculator.CalculateNeighbors(CubeViewModels);
}
else if (args.NewValue > CubeViewModels.Count) // adding cubes
{
AddNewCubes(numToChange);
Status = ReadyStatus;
SnapToGridCommand.Execute(null);
if (AppRunner.IsRunning)
{
AppRunner.App.AssociateCubes(CubeSet);
}
}
}
Status = ReadyStatus;
});
#endregion
#region SnapToGridCommand
SnapToGridCommand = new RelayCommand(() =>
{
Status = Strings.SnappingStatus;
for (var i = 0; i < Math.Ceiling(CubeViewModels.Count / 4.0); i++)
{
for (var j = 0; j < 4; j++)
{
if ((i * 4) + j > CubeViewModels.Count - 1)
{
NeighborCalculator.CalculateNeighbors(CubeViewModels);
Status = ReadyStatus;
return;
}
CubeViewModels[(i * 4) + j].PositionX = 200 * j;
CubeViewModels[(i * 4) + j].PositionY = 200 * i;
}
}
NeighborCalculator.CalculateNeighbors(CubeViewModels);
Status = ReadyStatus;
});
#endregion
#region LoadAFileCommand
LoadAFileCommand = new RelayCommand(() =>
{
if (AppRunner.IsRunning)
{
AppRunner.StopExecution();
}
Status = Strings.SelectAppStatus;
var openFileDialog = new OpenFileDialog
{
Filter = "C# Library (*.dll)|*.dll|All Files (*.*)|*.*",
FilterIndex = 1,
Multiselect = false
};
if (openFileDialog.ShowDialog() == true)
{
Status = Strings.LoadingStatus;
using (var fileStream = openFileDialog.File.OpenRead())
{
try
{
AppRunner.LoadApplication(fileStream);
}
catch (TypeLoadException e)
{
Status = String.Format(Strings.LoadingError + ": {0}", e.Message);
}
}
if (AppRunner.IsLoaded)
{
Status = Strings.LoadingImagesStatus;
if (openFileDialog.File.Directory != null)
{
_imageSources =
new ImageSources(openFileDialog.File.Directory.FullName + "\\assets\\images");
SoundSources =
new SoundSources(openFileDialog.File.Directory.FullName + "\\assets\\sounds", ActiveSounds, InactiveSounds);
AppRunner.App.Images = (ImageSet) _imageSources.GetMediaSet();
foreach (var cubeViewModel in CubeViewModels)
{
cubeViewModel.ImageSources = _imageSources;
}
//.........这里部分代码省略.........
示例8: ShelveServiceModel
public ShelveServiceModel(ITeamPilgrimServiceModelProvider teamPilgrimServiceModelProvider,
ITeamPilgrimVsService teamPilgrimVsService,
ProjectCollectionServiceModel projectCollectionServiceModel, WorkspaceServiceModel workspaceServiceModel)
: base(teamPilgrimServiceModelProvider, teamPilgrimVsService)
{
_projectCollectionServiceModel = projectCollectionServiceModel;
_workspaceServiceModel = workspaceServiceModel;
var versionControlServer = _projectCollectionServiceModel.TfsTeamProjectCollection.GetService<VersionControlServer>();
versionControlServer.PendingChangesChanged += VersionControlServerOnPendingChangesChanged;
_filterSolution = workspaceServiceModel.FilterSolution;
_selectedWorkWorkItemQueryDefinition = workspaceServiceModel.SelectedWorkItemQueryDefinition;
_comment = workspaceServiceModel.Comment;
EvaluateCheckInCommand = new RelayCommand(EvaluateCheckIn, CanEvaluateCheckIn);
ShowSelectWorkItemQueryCommand = new RelayCommand(ShowSelectWorkItemQuery, CanShowSelectWorkItemQuery);
RefreshPendingChangesCommand = new RelayCommand(RefreshPendingChanges, CanRefreshPendingChanges);
RefreshSelectedDefinitionWorkItemsCommand = new RelayCommand(RefreshSelectedDefinitionWorkItems, CanRefreshSelectedDefinitionWorkItems);
ShelveCommand = new RelayCommand(Shelve, CanShelve);
CancelCommand = new RelayCommand(Cancel, CanCancel);
SelectPendingChangesCommand = new RelayCommand<SelectPendingChangesCommandArgument>(SelectPendingChanges, CanSelectPendingChanges);
SelectWorkItemsCommand = new RelayCommand<SelectWorkItemsCommandArgument>(SelectWorkItems, CanSelectWorkItems);
CompareWithLatestCommand = new RelayCommand<ObservableCollection<object>>(CompareWithLatest, CanCompareWithLatest);
CompareWithWorkspaceCommand = new RelayCommand<ObservableCollection<object>>(CompareWithWorkspace, CanCompareWithWorkspace);
UndoPendingChangeCommand = new RelayCommand<ObservableCollection<object>>(UndoPendingChange, CanUndoPendingChange);
PendingChangePropertiesCommand = new RelayCommand<ObservableCollection<object>>(PendingChangeProperties, CanPendingChangeProperties);
CheckinNotes = new ObservableCollection<CheckinNoteModel>();
PendingChanges = new ObservableCollection<PendingChangeModel>();
foreach (var pendingChangeModel in workspaceServiceModel.PendingChanges)
{
PendingChanges.Add(new PendingChangeModel(pendingChangeModel.Change)
{
IncludeChange = pendingChangeModel.IncludeChange
});
}
PendingChanges.CollectionChanged += PendingChangesOnCollectionChanged;
WorkItems = new ObservableCollection<WorkItemModel>();
foreach (var workItemModel in workspaceServiceModel.WorkItems)
{
WorkItems.Add(new WorkItemModel(workItemModel.WorkItem)
{
IsSelected = workItemModel.IsSelected,
WorkItemCheckinAction = workItemModel.WorkItemCheckinAction
});
}
WorkItems.CollectionChanged += WorkItemsOnCollectionChanged;
SolutionIsOpen = teamPilgrimVsService.Solution.IsOpen && !string.IsNullOrEmpty(teamPilgrimVsService.Solution.FileName);
teamPilgrimVsService.SolutionStateChanged += () =>
{
FilterSolution = false;
SolutionIsOpen = teamPilgrimVsService.Solution.IsOpen && !string.IsNullOrEmpty(teamPilgrimVsService.Solution.FileName);
};
PopulatePreviouslySelectedWorkItemQueryModels();
PopulateSelectedPendingChangesSummary();
EvaluateCheckInCommand.Execute(null);
}
示例9: TestCallingExecuteWhenCanExecuteIsFalse
public void TestCallingExecuteWhenCanExecuteIsFalse()
{
var result = string.Empty;
const string value1 = "Hello";
const string value2 = "World";
var command = new RelayCommand<string>(
s => result = s,
s => _canExecute);
command.Execute(value1);
Assert.AreEqual(value1, result);
_canExecute = false;
command.Execute(value2);
Assert.AreEqual(value1, result);
_canExecute = true;
command.Execute(value2);
Assert.AreEqual(value2, result);
}
示例10: ExecuteTest
public void ExecuteTest()
{
var dummy = "Not executed";
const string executed = "Executed";
const string parameter = "Parameter";
var command = new RelayCommand<string>(p =>
{
dummy = executed + p;
});
command.Execute(parameter);
Assert.AreEqual(executed + parameter, dummy);
}
示例11: TestValueTypeConversion
public void TestValueTypeConversion()
{
Reset();
const int inputInt = 1234;
const double inputDouble = 1234.5678;
const bool inputBool = true;
var resultInt = 0;
var resultBool = false;
var resultDouble = 0.0;
var commandInt = new RelayCommand<int>(
p =>
{
resultInt = p;
},
p => true);
var commandBool = new RelayCommand<bool>(
p =>
{
resultBool = p;
},
p => true);
var commandDouble = new RelayCommand<double>(
p =>
{
resultDouble = p;
},
p => true);
Assert.AreEqual(0, resultInt);
Assert.AreEqual(false, resultBool);
Assert.AreEqual(0.0, resultDouble);
commandInt.Execute(inputInt.ToString());
commandBool.Execute(inputBool.ToString());
commandDouble.Execute(inputDouble.ToString());
Assert.AreEqual(inputInt, resultInt);
Assert.AreEqual(inputBool, resultBool);
Assert.AreEqual(inputDouble, resultDouble);
}
示例12: TestValueTypeCanExecute
public void TestValueTypeCanExecute()
{
Reset();
var command = new RelayCommand<int>(
i => _methodWasExecuted = true,
i => true);
Assert.IsFalse(_methodWasExecuted);
command.Execute(null);
Assert.IsTrue(_methodWasExecuted);
}
示例13: MainViewModel
public MainViewModel()
{
refreshCommand = new RelayCommand(async () => await RefreshItems());
refreshCommand.Execute(0);
}
示例14: MainWindowViewModel
public MainWindowViewModel()
{
#region ChangeNumberOfCubesCommand
ChangeNumberOfCubesCommand = new RelayCommand<EventArgs>(e =>
{
Status = "Changing number of cubes";
var args = e as RoutedPropertyChangedEventArgs<double>;
if (args != null)
{
var numToChange = Math.Abs(Convert.ToInt32(CubeViewModels.Count - args.NewValue));
if (args.NewValue < CubeViewModels.Count) // removing cubes
{
for (var i = 0; i < numToChange; i++)
{
CubeViewModels.RemoveAt(CubeViewModels.Count - 1);
}
NeighborCalculator.CalculateNeighbors(CubeViewModels);
}
else if (args.NewValue > CubeViewModels.Count) // adding cubes
{
AddNewCubes(numToChange);
Status = ReadyStatus;
SnapToGridCommand.Execute(null);
if (AppRunner.IsRunning)
{
AppRunner.App.AssociateCubes(CubeSet);
}
}
}
Status = ReadyStatus;
});
#endregion
#region SnapToGridCommand
SnapToGridCommand = new RelayCommand(() =>
{
Status = "Snapping to grid";
for (var i = 0; i < Math.Ceiling(CubeViewModels.Count / 4.0); i++)
{
for (var j = 0; j < 4; j++)
{
if ((i * 4) + j > CubeViewModels.Count - 1)
{
NeighborCalculator.CalculateNeighbors(CubeViewModels);
Status = ReadyStatus;
return;
}
CubeViewModels[(i * 4) + j].PositionX = 200 * j;
CubeViewModels[(i * 4) + j].PositionY = 200 * i;
}
}
NeighborCalculator.CalculateNeighbors(CubeViewModels);
Status = ReadyStatus;
});
#endregion
#region LoadAFileCommand
LoadAFileCommand = new RelayCommand(() =>
{
if (AppRunner.IsRunning)
{
AppRunner.StopExecution();
}
Status = "Select the application to run.";
var openFileDialog = new OpenFileDialog
{
Filter = "C# Library (*.dll)|*.dll|All Files (*.*)|*.*",
FilterIndex = 1,
Multiselect = false
};
if (openFileDialog.ShowDialog() == true)
{
Status = "Loading application...";
using (var fileStream = openFileDialog.File.OpenRead())
{
try
{
AppRunner.LoadApplication(fileStream);
}
catch (TypeLoadException e)
{
Status = String.Format("Unable to load application: {0}", e.Message);
}
}
if (AppRunner.IsLoaded)
{
Status = "Loading image resources...";
if (openFileDialog.File.Directory != null)
{
_imageSources =
new ImageSources(openFileDialog.File.Directory.FullName + "/assets/images");
SoundSources =
new SoundSources(openFileDialog.File.Directory.FullName + "/assets/sounds");
SoundSources.NotifyNewSound += sound =>
SoundSources.InitializeSound(sound, ActiveSounds, InactiveSounds);
Sound.NotifyPauseAllSounds += () => SoundSources.PauseAllSounds(ActiveSounds, InactiveSounds);
Sound.NotifyResumeAllSounds += () => SoundSources.ResumeAllSounds(ActiveSounds, InactiveSounds);
Sound.NotifyStopAllSounds += () => SoundSources.StopAllSounds(ActiveSounds, InactiveSounds);
//.........这里部分代码省略.........
示例15: InitializeCommands
private void InitializeCommands()
{
CloseWindowCommand = new RelayCommand(() => Application.Current.MainWindow.Close());
MinimizeWindowCommand = new RelayCommand(() => WindowState = WindowState.Minimized);
MaximizeWindowCommand = new RelayCommand(() => WindowState = IsWindowMaximized ? WindowState.Normal : WindowState.Maximized);
GoToPageCommand = new RelayCommand<string>(page => OnNavigateToPage(new NavigateToPageMessage() { Page = page }));
GoToSettingsCommand = new RelayCommand(() =>
{
ShowSidebar = false;
OnNavigateToPage(new NavigateToPageMessage() { Page = "/Settings.SettingsView" });
});
PrevAudioCommand = new RelayCommand(AudioService.Prev);
NextAudioCommand = new RelayCommand(AudioService.SkipNext);
PlayPauseCommand = new RelayCommand(() =>
{
if (IsPlaying)
AudioService.Pause();
else
AudioService.Play();
});
GoBackCommand = new RelayCommand(() =>
{
var frame = Application.Current.MainWindow.GetVisualDescendents().OfType<Frame>().FirstOrDefault(f => f.Name == "RootFrame");
if (frame == null)
return;
if (frame.CanGoBack)
frame.GoBack();
UpdateCanGoBack();
});
SearchCommand = new RelayCommand<string>(query =>
{
if (!string.IsNullOrWhiteSpace(query))
{
MessengerInstance.Send(new NavigateToPageMessage()
{
Page = "/Search.SearchResultsView",
Parameters = new Dictionary<string, object>()
{
{"query", query}
}
});
}
});
SearchKeyUpCommand = new RelayCommand<KeyEventArgs>(args =>
{
if (args.Key == Key.Enter)
{
var textBox = args.Source as TextBox;
if (textBox != null && !string.IsNullOrWhiteSpace(textBox.Text))
SearchCommand.Execute(textBox.Text);
}
});
RestartCommand = new RelayCommand(() =>
{
Process.Start(Application.ResourceAssembly.Location);
Application.Current.Shutdown();
});
AddRemoveAudioCommand = new RelayCommand<VkAudio>(audio =>
{
audio.IsAddedByCurrentUser = !audio.IsAddedByCurrentUser;
LikeDislikeAudio(audio);
});
EditAudioCommand = new RelayCommand<VkAudio>(audio =>
{
var flyout = new FlyoutControl();
flyout.FlyoutContent = new EditAudioView(audio);
flyout.Show();
});
ShowLyricsCommand = new RelayCommand<VkAudio>(audio =>
{
var flyout = new FlyoutControl();
flyout.FlyoutContent = new LyricsView(audio);
flyout.Show();
});
CopyInfoCommand = new RelayCommand<Audio>(audio =>
{
if (audio == null)
return;
try
{
Clipboard.SetData(DataFormats.UnicodeText, audio.Artist + " - " + audio.Title);
}
//.........这里部分代码省略.........