Skip to content

Instantly share code, notes, and snippets.

View SmashBrando's full-sized avatar

Brandon Kidd SmashBrando

  • Fort Collins, Colorado
View GitHub Profile
<TreeView ...    local:CheckBoxTreeViewItem.Checked="item_Checked"
<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>
public BindToClickEventCommand CheckedEvent
{
get
{
return new BindToClickEventCommand(TreeView);
}
}
public class BindToClickEventCommand : ICommand
{
private Action _handler;
public ViewModelCommand(Control control)
{
// Get the control's Type
Type someTreeViewType = ((UIElement)control).GetType();
// 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
// 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);
@SmashBrando
SmashBrando / CheckedTreeViewItem.cs
Created August 13, 2021 15:43
CheckedTreeViewItem
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Controls;
public class CheckedTreeViewItem : ItemsControl, INotifyPropertyChanged
{
bool? _isChecked = false;
@SmashBrando
SmashBrando / HierarchicalDataTemplate.aspx
Created August 13, 2021 15:35
HierarchicalDataTemplate
<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"/>
<ContentPresenter Content="{Binding Text, Mode=TwoWay}" Margin="2,0" />
</StackPanel>
</HierarchicalDataTemplate>
@SmashBrando
SmashBrando / functions.php
Last active February 5, 2020 16:27
Google Trusted Stores - Woocommerce Thank You Page Output
<?php
add_action( 'woocommerce_thankyou', 'google_trusted_stores_confirmation' );
function google_trusted_stores_confirmation( $order_id ) {
// Lets grab the order
$order = wc_get_order( $order_id );
$customer = get_current_user_id();