Skip to content

Instantly share code, notes, and snippets.

@jsonw23
Created April 27, 2012 01:44
Show Gist options
  • Save jsonw23/2504956 to your computer and use it in GitHub Desktop.
Save jsonw23/2504956 to your computer and use it in GitHub Desktop.
Folder Tree WPF Control: Part 2 - Selection Events
public partial class FolderTree : UserControl
{
private FolderTreeSelection _selection;
public FolderTreeSelection Selection
{
get { return _selection; }
set
{
_selection = value;
_selection.Changed += new EventHandler(OnSelectionChanged);
}
}
public event EventHandler SelectionChanged;
public FolderTree()
{
InitializeComponent();
Selection = new FolderTreeSelection();
}
...
private void OnSelectionChanged(object sender, EventArgs args)
{
if (SelectionChanged != null)
{
SelectionChanged(sender, args);
}
}
}
public class FolderTreeSelection : ViewModelBase
{
...
public event EventHandler Changed;
...
private void OnChanged()
{
if (Changed != null)
{
Changed(this, new EventArgs());
}
}
}
<Window x:Class="Demo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ftc="clr-namespace:GeekJ.FolderTreeControl;assembly=GeekJ.FolderTreeControl"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ftc:FolderTree SelectionChanged="FolderTreeSelection_Changed" />
</Grid>
</Window>
<Window x:Class="Demo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ftc="clr-namespace:GeekJ.FolderTreeControl;assembly=GeekJ.FolderTreeControl"
xmlns:ftcModel="clr-namespace:GeekJ.FolderTreeControl.Model;assembly=GeekJ.FolderTreeControl"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ftc:FolderTree>
<ftc:FolderTree.Selection>
<ftcModel:FolderTreeSelection Changed="FolderTreeSelection_Changed" />
</ftc:FolderTree.Selection>
</ftc:FolderTree>
</Grid>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment