WPF TwoWay Binding to a static class Property

Use the static property binding syntax (which is, as far as I know, available since WPF 4.5): <TextBox Text=”{Binding Path=(engine:ProjectData.Username)}”/> No need to set Mode=”TwoWay”, as that is the default for the TextBox.Text property anyway. Although not explicitly asked for, you may also want to implement property change notification. See this answer for how to … Read more

What are the differences between using the New keyword and calling CreateObject in Excel VBA?

As long as the variable is not typed as object Dim xmlDocument as MSXML2.DOMDocument Set xmlDocument = CreateObject(“MSXML2.DOMDocument”) is the same as Dim xmlDocument as MSXML2.DOMDocument Set xmlDocument = New MSXML2.DOMDocument both use early binding. Whereas Dim xmlDocument as Object Set xmlDocument = CreateObject(“MSXML2.DOMDocument”) uses late binding. See MSDN here. When you’re creating externally provided … Read more

Binding to DateTime.Now. Update the value

Here’s a link of a ‘Ticker’ class that uses INotifyPropertyChanged so it’ll auto-update. Here’s the code from the site: namespace TheJoyOfCode.WpfExample { public class Ticker : INotifyPropertyChanged { public Ticker() { Timer timer = new Timer(); timer.Interval = 1000; // 1 second updates timer.Elapsed += timer_Elapsed; timer.Start(); } public DateTime Now { get { return … Read more

Binding StringFormat

Since BindingBase.StringFormat is not a dependency property, I do not think that you can bind it. If the formatting string varies, I’m afraid you will have to resort to something like this <TextBlock Text=”{Binding MyFormattedProperty}” /> and do the formatting in your view model. Alternatively, you could use a MultiBinding and a converter (example code … Read more

WPF: How to bind a command to the ListBoxItem using MVVM?

Unfortunately, only ButtonBase derived controls have the possibility for binding ICommand objects to their Command properties (for the Click event). However, you can use an API provided by Blend to map an event (like in your case MouseDoubleClick on the ListBox) to an ICommand object. <ListBox> <i:Interaction.Triggers> <i:EventTrigger EventName=”MouseDoubleClick”> <i:InvokeCommandAction Command=”{Binding YourCommand}”/> </i:EventTrigger> </i:Interaction.Triggers> </ListBox> … Read more

WPF event binding from View to ViewModel?

One way to handle events in MVVM and XAML is to use the Blend Interactivity features. This namespace contains the InvokeCommandAction and the CallMethodAction classes. InvokeCommandAction lets you bind any event to a view-model command while CallMethodAction lets you bind any event to a view-model method. For example if you want to bind the DoubleClick … Read more

Property binding vs attribute interpolation

Property binding like [trueValue]=”…” evaluates the expression “…” and assigns the value “true” evaluates to the value true “Y” is unknown. There is no internal Y value in TypeScript and no property in the component class instance, which is the scope of template binding. In this case you would want [trueValue]=”‘Y'” Note the additional quotes … Read more