WPF + MVVM + RadioButton : How to handle binding with single property?

You need a IValueConverter. //define this in the Window’s Resources section or something similiarly suitable <local:GenderConverter x:Key=”genderConverterKey” /> <RadioButton Content=”M” IsChecked=”{Binding Gender, Converter={StaticResource ResourceKey=genderConverterKey}, ConverterParameter=M}” /> <RadioButton Content=”F” IsChecked=”{Binding Gender, Converter={StaticResource ResourceKey=genderConverterKey}, ConverterParameter=F}” /> The converter public class GenderConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return ((string)parameter … 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?.

Best way for automatic databinding between database and user interface in java swing app?

This is a complex topic that might make a good Community Wiki. I’ve only scratched the surface, but NetBeans has an evolving capability in this area. It should be on your short list. See these help topics & links: Generating JPA Controller Classes from Entity Classes Binding Data to a Swing Component Java Persistence Tasks: … Read more

Binding to custom control inside DataTemplate for ItemsControl

The problem is that you explicitly set the DataContext of your UserControl to itself: DataContext=”{Binding Mode=OneWay, RelativeSource={RelativeSource Self}} Remove that assignment and write the ItemName binding like this: <TextBlock Text=”{Binding ItemName, RelativeSource={RelativeSource AncestorType=UserControl}}”/> or like this <TextBlock Text=”{Binding ItemName, ElementName=ItemRowControl}”/>

Is there a way to determine where a WPF Binding is declared/created?

When debugging WPF binding errors, I find it easiest to break up the error by the semicolons, and start from the end System.Windows.Data Error: 4 : Cannot find source for binding with reference ‘RelativeSource FindAncestor, AncestorType=”System.Windows.Controls.ItemsControl”, AncestorLevel=”1″‘. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is ‘MenuItem’ (Name=””); target property is ‘HorizontalContentAlignment’ (type ‘HorizontalAlignment’) So starting from the end: … Read more

Databind a dropdownlist

string strQuery = “Select Item FROM Calendar Where UserD=’Test'”; Note you need to use single quotations around the string, as in your code you didn’t finish the inital string ever, so the rest of the code just became part of strQuery. In addition if you bring back more than one field in the future, when … Read more