Solution 1. Create a custom class which contains the collection and a bool property and set the DataContext to an instance of that class.
Solution 2. Set the user control's DataContext to the collection and add a bool property to your user control.
XAML:
<UserControl x:Class="DataContextDemo.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="self">
<StackPanel>
<ListBox ItemsSource="{Binding}" />
<CheckBox IsChecked="{Binding Path=MyBoolProp, ElementName=self}" />
</StackPanel>
</UserControl>
Code behind:
using System.Windows;
using System.Windows.Controls;
namespace DataContextDemo
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public bool MyBoolProp
{
get { return (bool)GetValue(MyBoolPropProperty); }
set { SetValue(MyBoolPropProperty, value); }
}
public static readonly DependencyProperty MyBoolPropProperty =
DependencyProperty.Register("MyBoolProp",
typeof(bool),
typeof(UserControl1),
new UIPropertyMetadata(true));
}
}