Skip to content

Instantly share code, notes, and snippets.

View SmashBrando's full-sized avatar

Brandon Kidd SmashBrando

  • Fort Collins, Colorado
View GitHub Profile
// This event uses the bubbling routing strategy
public static readonly RoutedEvent CheckedEvent = EventManager.RegisterRoutedEvent(
"Checked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TreeView));
public static void AddCheckedHandler(DependencyObject d, RoutedEventHandler handler)
{
UIElement uie = d as UIElement;
if (uie != null)
{
uie.AddHandler(CheckedTreeViewItem.CheckedEvent, handler);
// Get the control's Type
Type controlViewType = ((UIElement)control).GetType();
// Dig out the undocumented (yes, I know, it's risky) EventHandlerStore
// from the control's Type
PropertyInfo EventHandlersStoreType =
controlViewType.GetProperty("EventHandlersStore",
BindingFlags.Instance | BindingFlags.NonPublic);
// Get the actual "value" of the store, not just the reflected PropertyInfo
public class BindToClickEventCommand : ICommand
{
private Action _handler;
public ViewModelCommand(Control control)
{
// Get the control's Type
Type someTreeViewType = ((UIElement)control).GetType();
public BindToClickEventCommand CheckedEvent
{
get
{
return new BindToClickEventCommand(TreeView);
}
}
<HierarchicalDataTemplate x:Key="CheckBoxTreeViewItemTemplate" ItemsSource="{Binding Items, Mode=OneWay}" >
<StackPanel Orientation="Horizontal">
<Image Margin="2,0" Source="{Binding ImageSource, Mode=TwoWay}" />
<CheckBox Focusable="False" IsChecked="{Binding IsChecked}" VerticalAlignment="Center"
<span style="background-color: #ffff00;">Command="{Binding CheckedEvent}"</span>/>
<ContentPresenter Content="{Binding Text, Mode=TwoWay}" Margin="2,0" />
</StackPanel>
</HierarchicalDataTemplate>
<TreeView ...    local:CheckBoxTreeViewItem.Checked="item_Checked"