Binding in WPF to element of array specified by property

Another alternative is to use MultiBinding with a converter: <Window x:Class=”WpfApplication1.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:local=”clr-namespace:WpfApplication1″ Title=”MainWindow” Height=”350″ Width=”525″> <StackPanel Orientation=”Vertical”> <StackPanel.Resources> <local:FoodIndexConverter x:Key=”foodIndexConverter” /> </StackPanel.Resources> <TextBlock Text=”{Binding DessertIndex}” /> <TextBlock Text=”{Binding Food[2]}” /> <TextBlock> <TextBlock.Text> <MultiBinding Converter=”{StaticResource foodIndexConverter}”> <Binding Path=”DessertIndex” /> <Binding Path=”Food”/> </MultiBinding> </TextBlock.Text> </TextBlock> </StackPanel> </Window> Then in the code-behind, the converter is defined … Read more

WPF DataGrid RowHeader databinding

I tried both answers, and neither worked for me. Essentially what I had to do was mix them together. This works for me: <DataGrid name=”ui_dataGrid> <DataGrid.RowHeaderTemplate> <DataTemplate> <TextBlock Text=”{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}, Path=Item.Header}”/> </DataTemplate> </DataGrid.RowHeaderTemplate> </DataGrid> The trick is to find the ancestor DataGridRow, then Bind the TextBlock.Text attribute to its Item’s property that … Read more

Access viewModel in javascript function outside viewModel’s scope

You can always access it just by storing your viewmodel in a variable you can access, the module and revealing module patterns are nice, but you can just store it in an object that won’t conflict with other names (‘my’ here): my = { viewModel: new EmployeeViewModel() }; ko.applyBindings(my.viewModel); You had the right idea, you … Read more

How can I tell my DataTemplate to bind to a property in the PARENT ViewModel?

The answer is this: <DataTemplate x:Key=”CodeGenerationMenuTemplate”> <MenuItem Header=”{Binding Title}” Command=”{Binding DataContext.SwitchPageCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Menu}}}” CommandParameter=”{Binding Title}”/> </DataTemplate> I just saw that Nir had given me the syntax to solve the above issue on this question: What is the best way in MVVM to build a menu that displays various pages?.

Re-sort WPF DataGrid after bounded Data has changed

It took me the whole afternoon but I finally found a solution that is surprisingly simple, short and efficient: To control the behaviors of the UI control in question (here a DataGrid) one might simply use a CollectionViewSource. It acts as a kind of representative for the UI control inside your ViewModel without completely breaking … Read more

Binding ComboBox SelectedItem using MVVM

You seem to be unnecessarily setting properties on your ComboBox. You can remove the DisplayMemberPath and SelectedValuePath properties which have different uses. It might be an idea for you to take a look at the Difference between SelectedItem, SelectedValue and SelectedValuePath post here for an explanation of these properties. Try this: <ComboBox Name=”cbxSalesPeriods” ItemsSource=”{Binding SalesPeriods}” … Read more

Custom input and output on same name in Angular2 2 way binding

For this compact syntax to work the input and output need to follow specific naming rules [(mobile)]=”myParam” @Output(‘mobileChange’) emitter: EventEmitter<string> = new EventEmitter<string>(); @Input(‘mobile’) set setMobileValue(value) { this.msisdn_confirm = this.msisdn = value; } Renaming inputs and outputs by passing a string parameter to the decorator is discourages. Rather use @Output() mobileChange: EventEmitter<string> = new EventEmitter<string>(); … Read more

A better way of forcing data bound WPF ListBox to update?

I have a Listbox bound to an object property which is of type List<MyCustomType>() and I verified that the following code updates the listbox when the List is updated. void On_MyObjProperty_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { MyListBox.Items.Refresh(); } If you’re still facing issues, scan the VS IDE output window (Ctrl+W, O) and see if you can … Read more