Passing current scope to an AngularJS Service

To let the controller know when something async happens, use Angular promises. To provoke the $apply, you don’t need the scope, you can call $rootScope.$apply, as there is no difference calling it in a specific scope or in the root. Regarding the variable reading, it would be better if you received parameters. But you could … Read more

How to format number of decimal places in wpf using style/template?

You should use the StringFormat on the Binding. You can use either standard string formats, or custom string formats: <TextBox Text=”{Binding Value, StringFormat=N2}” /> <TextBox Text=”{Binding Value, StringFormat={}{0:#,#.00}}” /> Note that the StringFormat only works when the target property is of type string. If you are trying to set something like a Content property (typeof(object)), … Read more

ASP.NET Repeater bind List

Just use <%# Container.DataItem.ToString() %> If you are worried about null values you may want to refactor to this (.NET 6+) <asp:Repeater ID=”repeater” runat=”server”> <ItemTemplate> <%# Container.DataItem?.ToString() ?? string.Empty%> </ItemTemplate> </asp:Repeater> Note if you are using less than .NET 6 you cannot use the null-conditional operator Container.DataItem?.ToString()

How to format TimeSpan in XAML

The format string is intended to work on a DateTime, not a TimeSpan. You could change your code to work with DateTime.Now instead. Your xaml is fine: <TextBlock Text=”{Binding MyTime,StringFormat=HH:mm}”/> Update And from .Net 4 format a TimeSpan as follows: <TextBlock Text=”{Binding MyTime,StringFormat=hh\\:mm}”/>

How to set a binding in Code?

Replace: myBinding.Source = ViewModel.SomeString; with: myBinding.Source = ViewModel; Example: Binding myBinding = new Binding(); myBinding.Source = ViewModel; myBinding.Path = new PropertyPath(“SomeString”); myBinding.Mode = BindingMode.TwoWay; myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; BindingOperations.SetBinding(txtText, TextBox.TextProperty, myBinding); Your source should be just ViewModel, the .SomeString part is evaluated from the Path (the Path can be set by the constructor or by the … Read more

Angular 2 two way binding using ngModel is not working

Angular has released its final version on 15th of September. Unlike Angular 1 you can use ngModel directive in Angular 2 for two way data binding, but you need write it in a bit different way like [(ngModel)] (Banana in a box syntax). Almost all angular2 core directives doesn’t support kebab-case now instead you should … Read more

Android : Difference between DataBinding and ViewBinding

According to the official docs: ViewBinding Only binding views to code. DataBinding Binding data (from code) to views + ViewBinding (Binding views to code) There are three important differences With view binding, the layouts do not need a layout tag You can’t use viewbinding to bind layouts with data in xml (No binding expressions, no … Read more

Detecting WPF Validation Errors

This post was extremely helpful. Thanks to all who contributed. Here is a LINQ version that you will either love or hate. private void CanExecute(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = IsValid(sender as DependencyObject); } private bool IsValid(DependencyObject obj) { // The dependency object is valid if it has no errors and all // of … Read more

Access parent DataContext from DataTemplate

I had problems with the relative source in Silverlight. After searching and reading I did not find a suitable solution without using some additional Binding library. But, here is another approach for gaining access to the parent DataContext by directly referencing an element of which you know the data context. It uses Binding ElementName and … Read more