By inheritance, it's pretty easy to do.
Here's for example a datagrid that triggers a validate event on enter keystroke.
namespace SLCommon
{
public delegate void VaditateSelectionEventHandler(object sender, EventArgs e);
/// <summary>
/// Fires a validate event whenever the enter key or the left mouse button is pressed
/// </summary>
public class EventDatagrid : DataGrid
{
public event VaditateSelectionEventHandler Validate;
public EventDatagrid()
: base()
{
this.MouseLeftButtonUp += new MouseButtonEventHandler(OnMouseLeftButtonUp);
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Key != Key.Enter)
base.OnKeyDown(e);
else
{
e.Handled = true;
Validate(this, e);
}
}
protected void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Validate(this, e);
}
}
}
XAML side:
<slc:EventDatagrid x:Name="toto" Validate="toto_Validate"
AutoGenerateColumns="True" IsReadOnly="True" Width="auto" MaxHeight="300">
</slc:EventDatagrid>
Note the Validate event handler.
Here after you can add a control myobj in a xaml file (be sure to declare the right xmlns:
namespace on the top of your page) and set it's property.
Don't know about blend, but it sure works the same way.