How to disable a databound ListBox item based on a property value?

You can use ItemContainerStyle: <ListBox> <ListBox.ItemContainerStyle> <Style TargetType=”{x:Type ListBoxItem}”> <Style.Triggers> <DataTrigger Binding=”{Binding YourPropertyName}” Value=”False”> <Setter Property=”IsEnabled” Value=”False”/> </DataTrigger> </Style.Triggers> </Style> </ListBox.ItemContainerStyle> </ListBox>

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

Xamly determine if a ListBox.Items.Count > 0

The ListBox contains a HasItems property you can bind to. So you can just do this: <BooleanToVisibilityConverter x:Key=”BooleanToVisibility” /> … <ListBox Visibility=”{Binding HasItems, RelativeSource={RelativeSource Self}, Converter=BooleanToVisibility}” /> Or as a Trigger so you don’t need the converter: <ListBox> <ListBox.Style> <Style TargetType=”{x:Type ListBox}”> <Setter Property=”Visibility” Value=”Visible” /> <Style.Triggers> <DataTrigger Binding=”{Binding HasItems, RelativeSource={RelativeSource Self}}” Value=”False”> <Setter Property=”Visibility” … Read more

ListBoxItem produces “System.Windows.Data Error: 4” binding error

The easiest way to solve this is to ensure that your Listbox has a ItemContainerStyle. See the following example: <ListBox x:Name=”RecentItemsListBox” Grid.Row=”1″ BorderThickness=”0″ Margin=”2,0,0,0″ SelectionChanged=”RecentItemsListBox_SelectionChanged”> <ListBox.ItemContainerStyle> <Style TargetType=”{x:Type ListBoxItem}”> <Setter Property=”HorizontalContentAlignment” Value=”Left”/> <Setter Property=”VerticalContentAlignment” Value=”Center”/> </Style> </ListBox.ItemContainerStyle> … </ListBox> What happens is that your Items are being created, and by default they look for parent’s … Read more

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