How to force a WPF binding to refresh?

You can use binding expressions: private void ComboBox_Loaded(object sender, RoutedEventArgs e) { ((ComboBox)sender).GetBindingExpression(ComboBox.ItemsSourceProperty) .UpdateTarget(); } But as Blindmeis noted you can also fire change notifications, further if your collection implements INotifyCollectionChanged (for example implemented in the ObservableCollection<T>) it will synchronize so you do not need to do any of this.

How do I bind a WPF DataGrid to a variable number of columns?

Here’s a workaround for Binding Columns in the DataGrid. Since the Columns property is ReadOnly, like everyone noticed, I made an Attached Property called BindableColumns which updates the Columns in the DataGrid everytime the collection changes through the CollectionChanged event. If we have this Collection of DataGridColumn’s public ObservableCollection<DataGridColumn> ColumnCollection { get; private set; } … Read more

Pushing read-only GUI properties back into ViewModel

Yes, I’ve done this in the past with the ActualWidth and ActualHeight properties, both of which are read-only. I created an attached behavior that has ObservedWidth and ObservedHeight attached properties. It also has an Observe property that is used to do the initial hook-up. Usage looks like this: <UserControl … SizeObserver.Observe=”True” SizeObserver.ObservedWidth=”{Binding Width, Mode=OneWayToSource}” SizeObserver.ObservedHeight=”{Binding … Read more

How can I set the text of a WPF Hyperlink via data binding?

It looks strange, but it works. We do it in about 20 different places in our app. Hyperlink implicitly constructs a <Run/> if you put text in its “content”, but in .NET 3.5 <Run/> won’t let you bind to it, so you’ve got to explicitly use a TextBlock. <TextBlock> <Hyperlink Command=”local:MyCommands.ViewDetails” CommandParameter=”{Binding}”> <TextBlock Text=”{Binding Path=Name}”/> … Read more

Is there a way to chain multiple value converters in XAML?

I used this method by Gareth Evans in my Silverlight project. Here’s my implementation of it: public class ValueConverterGroup : List<IValueConverter>, IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return this.Aggregate(value, (current, converter) => converter.Convert(current, targetType, parameter, culture)); } public object ConvertBack(object value, Type targetType, object parameter, … Read more

Spring MVC type conversion : PropertyEditor or Converter?

With all these drawbacks, why using Converters ? Am I missing something ? Are there other tricks that I am not aware of ? No, I think you have very comprehensively described both PropertyEditor and Converter, how each one is declared and registered. In my mind, PropertyEditors are limited in scope – they help convert … Read more

Binding a Button’s visibility to a bool value in ViewModel

Assuming AdvancedFormat is a bool, you need to declare and use a BooleanToVisibilityConverter: <!– In your resources section of the XAML –> <BooleanToVisibilityConverter x:Key=”BoolToVis” /> <!– In your Button declaration –> <Button Height=”50″ Width=”50″ Style=”{StaticResource MyButtonStyle}” Command=”{Binding SmallDisp}” CommandParameter=”{Binding}” Cursor=”Hand” Visibility=”{Binding Path=AdvancedFormat, Converter={StaticResource BoolToVis}}”/> Note the added Converter={StaticResource BoolToVis}. This is a very common pattern … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)