本文整理汇总了C#中GalaSoft.MvvmLight.Helpers.Binding类的典型用法代码示例。如果您正苦于以下问题:C# Binding类的具体用法?C# Binding怎么用?C# Binding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Binding类属于GalaSoft.MvvmLight.Helpers命名空间,在下文中一共展示了Binding类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SetupBindings
protected virtual void SetupBindings()
{
_isConnectedBinding = this.SetBinding(() => DeviceVm.IsConnected).WhenSourceChanges(() =>
{
System.Diagnostics.Debug.WriteLine("SubDeviceViewControllerBase: DeviceViewModel PropertyChanged IsConnected");
var navService = ServiceLocator.Current.GetInstance<INavigationService>();
if (!DeviceVm.IsConnected && navService.CurrentPageKey == _viewPageKey)
{
System.Diagnostics.Debug.WriteLine("Navigating back since device is not connected anymore.");
navService.GoBack();
}
});
_isConnectedBinding.ForceUpdateValueFromSourceToTarget();
_programModeBinding = this.SetBinding(() => DeviceVm.ProgramMode).WhenSourceChanges(() =>
{
System.Diagnostics.Debug.WriteLine("SubDeviceViewControllerBase: DeviceViewModel PropertyChanged ProgramMode");
var navService = ServiceLocator.Current.GetInstance<INavigationService>();
if (_programMode != MoCoBusProgramMode.Invalid && DeviceVm.ProgramMode != _programMode && navService.CurrentPageKey == _viewPageKey)
{
System.Diagnostics.Debug.WriteLine("Navigating back since ProgramMode was changed to another mode");
navService.GoBack();
}
});
_programModeBinding.ForceUpdateValueFromSourceToTarget();
}
开发者ID:milindur,项目名称:MdkControlApp,代码行数:28,代码来源:SubDeviceTableViewControllerBase.cs
示例2: SetCommand_OnBarButtonWithBinding_ParameterShouldUpdate
public void SetCommand_OnBarButtonWithBinding_ParameterShouldUpdate()
{
var value = DateTime.Now.Ticks.ToString();
var vmSource = new TestViewModel
{
Model = new TestModel
{
MyProperty = value
}
};
var vmTarget = new TestViewModel();
var control = new UIBarButtonItemEx();
var binding = new Binding<string, string>(
vmSource,
() => vmSource.Model.MyProperty);
control.SetCommand(
"Clicked",
vmTarget.SetPropertyCommand,
binding);
Assert.IsNull(vmTarget.TargetProperty);
control.PerformEvent();
Assert.AreEqual(value, vmTarget.TargetProperty);
value += "Test";
vmSource.Model.MyProperty = value;
control.PerformEvent();
Assert.AreEqual(value, vmTarget.TargetProperty);
}
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:34,代码来源:SetCommandTest.cs
示例3: Binding_Test1_Error
public void Binding_Test1_Error()
{
Vm = new AccountViewModel();
#if ANDROID
Operation = new EditText(Application.Context);
ChildName = new EditText(Application.Context);
#elif __IOS__
Operation = new UITextView();
ChildName = new UITextView();
#endif
_binding1 = this.SetBinding(
() => Vm.FormattedOperation,
() => Operation.Text);
_binding2 = this.SetBinding(
() => Vm.AccountDetails.Name,
() => ChildName.Text,
fallbackValue: "Fallback",
targetNullValue: "TargetNull");
Assert.AreEqual(AccountViewModel.EmptyText, Operation.Text);
Assert.AreEqual(_binding2.FallbackValue, ChildName.Text);
Vm.SetAccount();
Assert.AreEqual(
AccountViewModel.NotEmptyText + Vm.AccountDetails.Balance + Vm.Amount,
Operation.Text);
Assert.AreEqual(Vm.AccountDetails.Name, ChildName.Text);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:32,代码来源:BindingAccountTest.cs
示例4: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.AddComment);
// Retrieve navigation parameter and set as current "DataContext"
Vm = GlobalNavigation.GetAndRemoveParameter<FlowerViewModel>(Intent);
// Avoid aggressive linker problem which removes the TextChanged event
CommentText.TextChanged += (s, e) =>
{
};
_saveBinding = this.SetBinding(
() => CommentText.Text);
// Avoid aggressive linker problem which removes the Click event
SaveCommentButton.Click += (s, e) =>
{
};
SaveCommentButton.SetCommand(
"Click",
Vm.SaveCommentCommand,
_saveBinding);
}
开发者ID:dbremner,项目名称:mvvmlight,代码行数:26,代码来源:AddCommentActivity.cs
示例5: Binding_ConverterWithFallbackValue_ErrorInConverterShouldUseFallbackValue
public void Binding_ConverterWithFallbackValue_ErrorInConverterShouldUseFallbackValue()
{
var vmSource = new TestViewModel
{
Model = new TestModel
{
MyProperty = "Initial value"
}
};
var vmTarget = new TestViewModel();
const string fallbackValue = "Fallback value";
const string targetNullValue = "Target null value";
_binding = new Binding<string, string>(
vmSource,
() => vmSource.Model.MyProperty,
vmTarget,
() => vmTarget.TargetProperty,
BindingMode.Default,
fallbackValue,
targetNullValue)
.ConvertSourceToTarget(
value =>
{
throw new InvalidCastException("Only for test");
});
Assert.AreEqual(fallbackValue, vmTarget.TargetProperty);
vmSource.Model.MyProperty = "New value";
Assert.AreEqual(fallbackValue, vmTarget.TargetProperty);
}
开发者ID:dsfranzi,项目名称:MVVMLight,代码行数:35,代码来源:BindingTest.cs
示例6: Binding_MultipleLevelsOfNull_ShouldUseFallbackValueThenTargetNullValue
public void Binding_MultipleLevelsOfNull_ShouldUseFallbackValueThenTargetNullValue()
{
var vmSource = new TestViewModel();
var vmTarget = new TestViewModel();
const string fallbackValue = "Fallback value";
const string targetNullValue = "Target null value";
_binding = new Binding<string, string>(
vmSource,
() => vmSource.Nested.Model.MyProperty,
vmTarget,
() => vmTarget.TargetProperty,
BindingMode.Default,
fallbackValue,
targetNullValue);
Assert.AreEqual(fallbackValue, vmTarget.TargetProperty);
vmSource.Nested = new TestViewModel();
Assert.AreEqual(fallbackValue, vmTarget.TargetProperty);
vmSource.Nested.Model = new TestModel();
Assert.AreEqual(targetNullValue, vmTarget.TargetProperty);
vmSource.Nested.Model.MyProperty = DateTime.Now.Ticks.ToString();
Assert.AreEqual(vmSource.Nested.Model.MyProperty, vmTarget.TargetProperty);
}
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:25,代码来源:BindingTest.cs
示例7: Binding_TwoWayFromEditTextToEditTextWithObserveEvent_BindingGetsUpdated
public void Binding_TwoWayFromEditTextToEditTextWithObserveEvent_BindingGetsUpdated()
{
var control1 = new EditText(Application.Context);
var control2 = new EditText(Application.Context);
var binding = new Binding<string, string>(
control1,
() => control1.Text,
control2,
() => control2.Text,
BindingMode.TwoWay)
.ObserveSourceEvent<View.LongClickEventArgs>("LongClick")
.ObserveTargetEvent<View.LongClickEventArgs>("LongClick");
Assert.AreEqual(string.Empty, control1.Text);
Assert.AreEqual(control1.Text, control2.Text);
var value = DateTime.Now.Ticks.ToString();
control1.Text = value;
Assert.AreEqual(value, control1.Text);
Assert.AreEqual(string.Empty, control2.Text);
control1.PerformLongClick();
Assert.AreEqual(control1.Text, control2.Text);
var newValue = value + "Suffix";
control2.Text = newValue;
Assert.AreEqual(newValue, control2.Text);
Assert.AreEqual(value, control1.Text);
control2.PerformLongClick();
Assert.AreEqual(control2.Text, control1.Text);
}
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:30,代码来源:ObserveEventNonDefaultEventTest.cs
示例8: DetachBindings
protected virtual void DetachBindings()
{
_isConnectedBinding?.Detach();
_isConnectedBinding = null;
_programModeBinding?.Detach();
_programModeBinding = null;
}
开发者ID:milindur,项目名称:MdkControlApp,代码行数:8,代码来源:SubDeviceTableViewControllerBase.cs
示例9: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Set bindings
NameBinding = this.SetBinding(() => NoteViewModel.CurrentNote.Title, () => lblTitle.Text);
DateBinding = this.SetBinding(() => NoteViewModel.CurrentNote.DateString, () => lblDate.Text);
ContentBinding = this.SetBinding(() => NoteViewModel.CurrentNote.Content, () => lblContent.Text);
}
开发者ID:MicrosoftDXGermany,项目名称:Cross-Platform,代码行数:9,代码来源:DetailsViewController.cs
示例10: SetViewModel
public void SetViewModel (LogTimeEntriesViewModel viewModel)
{
ViewModel = viewModel;
// TODO: investigate why WhenSourceChanges doesn't work. :(
isRunningBinding = this.SetBinding (() => ViewModel.IsTimeEntryRunning, () => IsRunning);
durationBinding = this.SetBinding (() => ViewModel.Duration, () => DurationTextView.Text);
descBinding = this.SetBinding (() => ViewModel.Description, () => DescriptionTextView.Text)
.ConvertSourceToTarget (desc => desc != string.Empty ? desc : activity.ApplicationContext.Resources.GetText (Resource.String.TimerComponentNoDescription));
projectBinding = this.SetBinding (() => ViewModel.ProjectName, () => ProjectTextView.Text)
.ConvertSourceToTarget (proj => proj != string.Empty ? proj : activity.ApplicationContext.Resources.GetText (Resource.String.TimerComponentNoProject));
}
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:12,代码来源:TimerComponent.cs
示例11: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
ButtonGet = FindViewById<Button>(Resource.Id.myButton);
UsernameText = FindViewById<EditText>(Resource.Id.username);
PasswordText = FindViewById<EditText>(Resource.Id.password);
ComboText = FindViewById<TextView>(Resource.Id.combo);
ProgressBar = FindViewById<ProgressBar>(Resource.Id.progressBar1);
//So things don't link out.
//Only needed if linking all
//UsernameText.TextChanged += (sender, e) => {};
//PasswordText.TextChanged += (sender, e) => {};
//ButtonGet.Click += (sender, e) => {};
ButtonGet.SetCommand("Click", VM.GetPeopleCommand);
unBind = this.SetBinding(() => VM.Username,
() => UsernameText.Text,
BindingMode.TwoWay);
passBind = this.SetBinding(() => VM.Password,
() => PasswordText.Text,
BindingMode.TwoWay);
combBind = this.SetBinding(() => VM.ComboDisplay,
() => ComboText.Text,
BindingMode.OneWay);
busyBind = this.SetBinding(() => VM.IsBusy).WhenSourceChanges(() =>
{
ButtonGet.Enabled = !VM.IsBusy;
if(VM.IsBusy)
ProgressBar.Visibility = ViewStates.Visible;
else
ProgressBar.Visibility = ViewStates.Invisible;
});
updatedBind = this.SetBinding(() => VM.People)
.WhenSourceChanges(() =>
{
RunOnUiThread(() =>Toast.MakeText(this, "Count: " + VM.People.Count, ToastLength.Short).Show());
});
}
开发者ID:jv9,项目名称:MotzCodesLive,代码行数:53,代码来源:MainActivity.cs
示例12: AndroidNotificationManager
public AndroidNotificationManager ()
{
ctx = ServiceContainer.Resolve<Context> ();
notificationManager = (NotificationManager)ctx.GetSystemService (Context.NotificationService);
runningBuilder = CreateRunningNotificationBuilder (ctx);
idleBuilder = CreateIdleNotificationBuilder (ctx);
propertyTracker = new PropertyChangeTracker ();
TimeEntryManager = ServiceContainer.Resolve<ActiveTimeEntryManager> ();
binding = this.SetBinding (() => TimeEntryManager.ActiveTimeEntry).WhenSourceChanges (OnActiveTimeEntryChanged);
var bus = ServiceContainer.Resolve<MessageBus> ();
subscriptionSettingChanged = bus.Subscribe<SettingChangedMessage> (OnSettingChanged);
}
开发者ID:BradChang,项目名称:mobile,代码行数:14,代码来源:AndroidNotificationManager.cs
示例13: ViewDidLoad
public override void ViewDidLoad()
{
View = new UniversalView();
base.ViewDidLoad();
InitializeComponent();
Title = "Add comment";
_commentBinding = this.SetBinding(
() => CommentText.Text)
.UpdateSourceTrigger("Changed");
SaveCommentButton.SetCommand("Clicked", Vm.SaveCommentCommand, _commentBinding);
}
开发者ID:dbremner,项目名称:mvvmlight,代码行数:14,代码来源:AddCommentViewController.cs
示例14: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
_messageBinding = this.SetBinding(() => EditMessage.Text, BindingMode.TwoWay);
MessageButton.SetCommand("Click", Vm.MessageCommand, _messageBinding);
_textViewBinding = this.SetBinding(() => Vm.PreviousMessage, () => PreviousMessage.Text);
}
开发者ID:jardelsobrinho,项目名称:MvvmLightSamples,代码行数:14,代码来源:MainActivity.cs
示例15: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
CommandButton.SetCommand("Click", ViewModel.ShowDialogCommand);
_messageBinding = this.SetBinding(() => ViewModel.Message, () => MessageView.Text, BindingMode.OneWay);
}
开发者ID:chenjianwp,项目名称:UWP-MVVMSamples,代码行数:14,代码来源:MainActivity.cs
示例16: ViewDidLoad
public async override void ViewDidLoad ()
{
base.ViewDidLoad ();
ViewModel = await NewProjectViewModel.Init (workspaceId);
clientBinding = this.SetBinding (() => ViewModel.ClientName).WhenSourceChanges (() => {
var name = string.IsNullOrEmpty (ViewModel.ClientName) ? "NewProjectClientHint".Tr () : ViewModel.ClientName;
if (string.IsNullOrEmpty (ViewModel.ClientName)) {
clientButton.Apply (Style.NewProject.ClientButton).Apply (Style.NewProject.NoClient);
} else {
clientButton.Apply (Style.NewProject.WithClient);
}
clientButton.SetTitle (name, UIControlState.Normal);
});
}
开发者ID:eatskolnikov,项目名称:mobile,代码行数:15,代码来源:NewProjectViewController.cs
示例17: OnCreateActivity
protected override void OnCreateActivity (Bundle state)
{
base.OnCreateActivity (state);
SetContentView (Resource.Layout.IntroLayout);
FindViewById<TextView> (Resource.Id.IntroTitle).SetFont (Font.DINMedium);
FindViewById<TextView> (Resource.Id.IntroLoginText).SetFont (Font.DINMedium);
LoginButton = FindViewById<Button> (Resource.Id.LoginButton).SetFont (Font.DINMedium);
StartNowButton = FindViewById<Button> (Resource.Id.StartNowButton).SetFont (Font.DINMedium);
LoginButton.Click += LoginButtonClick;
StartNowButton.Click += StartNowButtonClick;
ViewModel = IntroViewModel.Init ();
isAuthenticatedBinding = this.SetBinding (() => ViewModel.IsAuthenticated).WhenSourceChanges (StartAuth);
}
开发者ID:eatskolnikov,项目名称:mobile,代码行数:15,代码来源:IntroActivity.cs
示例18: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
Button.AccessibilityIdentifier = "myButton";
Button.SetCommand("TouchUpInside", VM.GetPeopleCommand);
unBind = this.SetBinding(() => VM.Username,
() => TextUsername.Text,
BindingMode.TwoWay)
.UpdateTargetTrigger("EditingChanged");
passBind = this.SetBinding(() => VM.Password,
() => TextPassword.Text,
BindingMode.TwoWay)
.UpdateTargetTrigger("EditingChanged");
combBind = this.SetBinding(() => VM.ComboDisplay,
() => LabelCombo.Text,
BindingMode.OneWay);
busyBind = this.SetBinding(() => VM.IsBusy).WhenSourceChanges(() =>
{
Button.Enabled = !VM.IsBusy;
if(VM.IsBusy)
ProgressBar.StartAnimating();
else
ProgressBar.StopAnimating();
});
updatedBind = this.SetBinding(() => VM.People)
.WhenSourceChanges(() =>
{
notificationView = new GCDiscreetNotificationView (
text: "There are " + VM.People.Count + " people",
activity: false,
presentationMode: GCDNPresentationMode.Bottom,
view: View
);
notificationView.ShowAndDismissAfter (1);
});
}
开发者ID:jv9,项目名称:MotzCodesLive,代码行数:48,代码来源:ViewController.cs
示例19: BindViewHolder
private void BindViewHolder(CachingViewHolder holder, GalleryItem item, int position)
{
var layoutRoot = holder.ItemView;
layoutRoot.Post(() =>
{
var width = layoutRoot.Width;
var layoutParams = layoutRoot.LayoutParameters;
layoutParams.Height = width;
layoutRoot.LayoutParameters = layoutParams;
});
var thumbnailView = holder.FindCachedViewById<ImageViewAsync>(Resource.Id.Thumbnail);
holder.DeleteBinding(thumbnailView);
var thumbnailBinding = new Binding<string, string>(item, () => item.Thumbnail)
.WhenSourceChanges(() => ImageService.Instance.LoadUrl(item.Thumbnail).Into(thumbnailView));
holder.SaveBinding(thumbnailView, thumbnailBinding);
}
开发者ID:akshay2000,项目名称:MonocleGiraffe,代码行数:16,代码来源:SubGalleryActivity.cs
示例20: OnCreateDialog
public override Dialog OnCreateDialog (Bundle savedInstanceState)
{
nameEditText = new EditText (Activity);
nameEditText.SetHint (Resource.String.CreateTagDialogHint);
nameEditText.InputType = InputTypes.TextFlagCapSentences;
nameEditText.TextChanged += OnNameEditTextTextChanged;
// Again we need to define binding inside OnCreateDialog
tagBinding = this.SetBinding (() => viewModel.TagName, () => nameEditText.Text, BindingMode.TwoWay);
return new AlertDialog.Builder (Activity)
.SetTitle (Resource.String.CreateTagDialogTitle)
.SetView (nameEditText)
.SetPositiveButton (Resource.String.CreateTagDialogOk, OnPositiveButtonClicked)
.Create ();
}
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:16,代码来源:CreateTagDialogFragment.cs
注:本文中的GalaSoft.MvvmLight.Helpers.Binding类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论