本文整理汇总了C#中ViewModelBase类的典型用法代码示例。如果您正苦于以下问题:C# ViewModelBase类的具体用法?C# ViewModelBase怎么用?C# ViewModelBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ViewModelBase类属于命名空间,在下文中一共展示了ViewModelBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PublicRoomsPage
public PublicRoomsPage(ViewModelBase viewModel)
: base(viewModel)
{
var listView = new BindableListView
{
ItemTemplate = new DataTemplate(() =>
{
var textCell = new TextCell();
textCell.SetBinding(TextCell.TextProperty, new Binding("Name"));
textCell.TextColor = Styling.BlackText;
//textCell.SetBinding(TextCell.DetailProperty, new Binding("Description"));
return textCell;
}),
SeparatorVisibility = SeparatorVisibility.None
};
listView.SetBinding(ListView.ItemsSourceProperty, new Binding("PublicRooms"));
listView.SetBinding(BindableListView.ItemClickedCommandProperty, new Binding("SelectRoomCommand"));
var loadingIndicator = new ActivityIndicator ();
loadingIndicator.SetBinding(ActivityIndicator.IsRunningProperty, new Binding("IsBusy"));
loadingIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, new Binding("IsBusy"));
Content = new StackLayout
{
Children =
{
loadingIndicator,
listView
}
};
}
示例2: CreateWindow
Window CreateWindow(ViewModelBase viewModel)
{
Type windowType;
lock (_viewMap)
{
if (!_viewMap.ContainsKey(viewModel.GetType()))
throw new ArgumentException("viewModel not registered");
windowType = _viewMap[viewModel.GetType()];
}
var window = (Window)Activator.CreateInstance(windowType);
window.DataContext = viewModel;
window.Closed += OnClosed;
lock (_openedWindows)
{
// Last window opened is considered the 'owner' of the window.
// May not be 100% correct in some situations but it is more
// then good enough for handling dialog windows
if (_openedWindows.Count > 0)
{
Window lastOpened = _openedWindows[_openedWindows.Count - 1];
if (window != lastOpened)
window.Owner = lastOpened;
}
_openedWindows.Add(window);
}
// Listen for the close event
Messenger.Default.Register<RequestCloseMessage>(window, viewModel, OnRequestClose);
return window;
}
示例3: ShowViewModel
public bool ShowViewModel(string title, ViewModelBase viewModel)
{
var win = new DialogWindow(viewModel) {Title = title};
win.ShowDialog();
return win.CloseResult;
}
示例4: EquipmentRightViewModel
public EquipmentRightViewModel(ViewModelBase parent)
{
Parent = parent;
Label11 = "Asset ID:";
Label21 = "Fed Form:";
Label12 = "Equipment Type:";
Label22 = "Rated Voltage:";
Label13 = "Location:";
Label23 = "Problem?:";
Equipment equipment = ((EquipmentViewModel)Parent).SelectedEquipment;
TextBox11 = equipment.Asset_ID;
//TextBox21 = equipment.f;
TextBox12 = equipment.EquipmentTypeID.ToString();
//TextBox22 = equipment;
TextBox13 = equipment.LocationID.ToString();
//TextBox23 = equipment;
SetTab1Page();
SetTab2Page();
SetTab3Page();
SetTab4Page();
SetTab5Page();
SetTab6Page();
SetTab7Page();
SetTab8Page();
}
示例5: Next
public static async Task<ViewModelBase> Next(LinkViewModel parentLink, ViewModelBase currentActual)
{
if (parentLink != null)
{
var viewModelContextService = ServiceLocator.Current.GetInstance<IViewModelContextService>();
var firstRedditViewModel = viewModelContextService.ContextStack.FirstOrDefault(context => context is RedditViewModel) as RedditViewModel;
if (firstRedditViewModel != null)
{
RepositionContextScroll(parentLink);
var imagesService = ServiceLocator.Current.GetInstance<IImagesService>();
var offlineService = ServiceLocator.Current.GetInstance<IOfflineService>();
var settingsService = ServiceLocator.Current.GetInstance<ISettingsService>();
ViewModelBase stackNext = null;
if (settingsService.OnlyFlipViewUnread && (stackNext = LinkHistory.Forward()) != null)
{
return stackNext;
}
else
{
var currentLinkPos = firstRedditViewModel.Links.IndexOf(parentLink);
var linksEnumerator = new NeverEndingRedditView(firstRedditViewModel, currentLinkPos, true);
var result = await MakeContextedTuple(imagesService, offlineService, settingsService, linksEnumerator);
LinkHistory.Push(currentActual);
return result;
}
}
}
return null;
}
示例6: MapViewModel
PivotItem MapViewModel(ViewModelBase viewModel)
{
var rvm = viewModel as RedditViewModel;
var plainHeader = rvm.Heading == "The front page of this device" ? "front page" : rvm.Heading.ToLower();
return new PivotItem { DataContext = viewModel, Header = rvm.IsTemporary ? "*" + plainHeader : plainHeader };
}
示例7: GotoReplyToPost
public void GotoReplyToPost(ViewModelBase currentContext, CommentsViewModel source)
{
source.CurrentlyFocused = source.AddReplyComment(null);
Messenger.Default.Send<FocusChangedMessage>(new FocusChangedMessage(source));
}
示例8: CheckForRatingsPromptAsync
/// <summary>
/// Executes business logic to determine if an instance of the application should prompt the user to solicit user ratings.
/// If it determines it should, the dialog to solicit ratings will be displayed.
/// </summary>
/// <returns>Awaitable task is returned.</returns>
public async Task CheckForRatingsPromptAsync(ViewModelBase vm)
{
bool showPrompt = false;
// PLACE YOUR CUSTOM RATE PROMPT LOGIC HERE!
this.LastPromptedForRating = Platform.Current.Storage.LoadSetting<DateTime>(LAST_PROMPTED_FOR_RATING);
// If trial, not expired, and less than 2 days away from expiring, set as TRUE
bool preTrialExpiredBasedPrompt =
Platform.Current.AppInfo.IsTrial
&& !Platform.Current.AppInfo.IsTrialExpired
&& DateTime.Now.AddDays(2) > Platform.Current.AppInfo.TrialExpirationDate;
if (preTrialExpiredBasedPrompt && this.LastPromptedForRating == DateTime.MinValue)
{
showPrompt = true;
}
else if (this.LastPromptedForRating != DateTime.MinValue && this.LastPromptedForRating.AddDays(21) < DateTime.Now)
{
// Every X days after the last prompt, set as TRUE
showPrompt = true;
}
else if(this.LastPromptedForRating == DateTime.MinValue && Windows.ApplicationModel.Package.Current.InstalledDate.DateTime.AddDays(3) < DateTime.Now)
{
// First time prompt X days after initial install
showPrompt = true;
}
if(showPrompt)
await this.PromptForRatingAsync(vm);
}
示例9: PageNavigationMessage
public PageNavigationMessage(ViewModelBase bindingViewModel, NavigationKind kind)
{
this.BindingViewModel = bindingViewModel;
if (kind == NavigationKind.Navigate)
throw new ArgumentException("Navigate は Pageを含むコンストラクタが必要です。");
this.Kind = kind;
}
示例10: MvvmableContentPage
public MvvmableContentPage(ViewModelBase viewModel)
{
_viewModel = viewModel;
BindingContext = viewModel;
Title = "SharedSquawk";
BackgroundColor = Styling.BackgroundColor;
}
示例11: WebViewBridge
public WebViewBridge(IWebView webView, ViewModelBase viewModel)
{
_webView = webView;
_bridge = new Bridge(viewModel, this);
_webView.NativeViewInitialized += (sender, args) => _webView.DocumentReady += (sender2, args2) => Initialize();
}
示例12: ProvideView
public static void ProvideView(ViewModelBase vm, ViewModelBase parentVm = null)
{
IViewMap map = Maps.SingleOrDefault(x => x.ViewModelType == vm.GetType());
if (map == null)
return;
var viewInstance = Activator.CreateInstance(map.ViewType) as Window;
if (viewInstance == null)
throw new InvalidOperationException(string.Format("Can not create an instance of {0}", map.ViewType));
if (parentVm != null)
{
ViewInstance parent = RegisteredViews.SingleOrDefault(x => x.ViewModel == parentVm);
if (parent != null)
{
Window parentView = parent.View;
if (Application.Current.Windows.OfType<Window>().Any(x => Equals(x, parentView)))
viewInstance.Owner = parentView;
}
}
viewInstance.DataContext = vm;
RegisteredViews.Add(new ViewInstance(viewInstance, vm));
viewInstance.Show();
}
示例13: Show
public bool Show(ViewModelBase viewModel, int windowHeight = 600, int windowWidth = 860)
{
if(_window == null)
_window = new WindowView();
var refreashable = viewModel as IRefreashable;
if (refreashable != null)
refreashable.Refreash();
if (_window.DataContext != null && _window.DataContext.Equals(viewModel))
{
return false;
}
if(_window.IsVisible)
{
_window.Focus();
return false;
}
_window.Height = windowHeight;
_window.Width = windowWidth;
_window.Title = viewModel.ToString();
_window.DataContext = viewModel;
var result = _window.ShowDialog();
_window = null;
return result == true;
}
示例14: ApplyTo
public void ApplyTo(ViewModelBase viewModel)
{
var dynamicObject = new DynamicObject(viewModel);
var commands = dynamicObject.GetProperties().Where(p => p.PropertyType == typeof (DelegateCommand));
foreach (var c in commands)
{
var command = c;
var executeMethodName = string.Format("On{0}", command.Name);
var canExecuteMethodName = string.Format("Can{0}", command.Name);
var delegateCommand = command.GetValue(viewModel, null) as DelegateCommand;
if (delegateCommand != null)
{
if (dynamicObject.MethodExist(executeMethodName))
{
delegateCommand.ExecuteDelegate = () =>
{
dynamicObject.InvokeMethod(executeMethodName);
};
}
if (dynamicObject.MethodExist(canExecuteMethodName))
{
delegateCommand.CanExecuteDelegate = () =>
{
return (bool)dynamicObject.InvokeMethod(canExecuteMethodName);
};
}
}
}
}
示例15: RegisterViewModel
/// <summary>
/// Initializes the view model and registers events so that the OnLoaded and OnUnloaded methods are called.
/// This method must be called in the constructor after the <see cref="InitializeComponent"/> method call.
/// </summary>
/// <param name="viewModel">The view model. </param>
/// <param name="view">The view. </param>
public static void RegisterViewModel(ViewModelBase viewModel, FrameworkElement view)
{
viewModel.Initialize();
view.Loaded += (sender, args) => viewModel.CallOnLoaded();
view.Unloaded += (sender, args) => viewModel.CallOnUnloaded();
}