Click here to Skip to main content
15,912,205 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: DispatcherTimer Tick event not fired Pin
Paulo Zemek23-Jan-13 6:28
Paulo Zemek23-Jan-13 6:28 
QuestionWhich way to load entity child collections? Pin
Adam_Dev16-Jan-13 5:11
Adam_Dev16-Jan-13 5:11 
QuestionWPF with Web Pin
Rishabh Kumar14-Jan-13 8:42
Rishabh Kumar14-Jan-13 8:42 
AnswerRe: WPF with Web Pin
Abhishek Pant14-Jan-13 9:17
professionalAbhishek Pant14-Jan-13 9:17 
AnswerRe: WPF with Web Pin
Abhinav S16-Jan-13 17:20
Abhinav S16-Jan-13 17:20 
QuestionWPF - Bind IsEnabled To Method On VM Pin
Kevin Marois13-Jan-13 11:06
professionalKevin Marois13-Jan-13 11:06 
AnswerRe: WPF - Bind IsEnabled To Method On VM Pin
Wayne Gaylard14-Jan-13 0:55
professionalWayne Gaylard14-Jan-13 0:55 
AnswerRe: WPF - Bind IsEnabled To Method On VM Pin
Richard Deeming14-Jan-13 2:13
mveRichard Deeming14-Jan-13 2:13 
GeneralRe: WPF - Bind IsEnabled To Method On VM Pin
Kevin Marois14-Jan-13 10:40
professionalKevin Marois14-Jan-13 10:40 
GeneralRe: WPF - Bind IsEnabled To Method On VM Pin
Kevin Marois20-Jan-13 8:47
professionalKevin Marois20-Jan-13 8:47 
QuestionWPF - Sync Combox Pin
Kevin Marois12-Jan-13 15:19
professionalKevin Marois12-Jan-13 15:19 
AnswerRe: WPF - Sync Combox Pin
Mycroft Holmes13-Jan-13 0:50
professionalMycroft Holmes13-Jan-13 0:50 
GeneralRe: WPF - Sync Combox Pin
Kevin Marois13-Jan-13 17:24
professionalKevin Marois13-Jan-13 17:24 
GeneralRe: WPF - Sync Combox Pin
Mycroft Holmes14-Jan-13 0:11
professionalMycroft Holmes14-Jan-13 0:11 
GeneralRe: WPF - Sync Combox Pin
Kevin Marois14-Jan-13 5:25
professionalKevin Marois14-Jan-13 5:25 
GeneralRe: WPF - Sync Combox Pin
SledgeHammer0114-Jan-13 9:34
SledgeHammer0114-Jan-13 9:34 
GeneralRe: WPF - Sync Combox Pin
Kevin Marois23-Jan-13 17:41
professionalKevin Marois23-Jan-13 17:41 
QuestionStyle From Resource File Not Being Applied Pin
Kevin Marois12-Jan-13 10:20
professionalKevin Marois12-Jan-13 10:20 
AnswerRe: Style From Resource File Not Being Applied Pin
Richard MacCutchan12-Jan-13 23:44
mveRichard MacCutchan12-Jan-13 23:44 
GeneralRe: Style From Resource File Not Being Applied Pin
Mycroft Holmes13-Jan-13 0:45
professionalMycroft Holmes13-Jan-13 0:45 
GeneralRe: Style From Resource File Not Being Applied Pin
Richard MacCutchan13-Jan-13 1:24
mveRichard MacCutchan13-Jan-13 1:24 
GeneralRe: Style From Resource File Not Being Applied Pin
Kevin Marois13-Jan-13 10:58
professionalKevin Marois13-Jan-13 10:58 
QuestionRoutedEvent vs AttachedEvent - Syntax difference only? Confused Pin
devvvy9-Jan-13 20:05
devvvy9-Jan-13 20:05 
Following example I managed to get fire both a RoutedEvent and an AttachedEvent from "GrandChild" and have them handled in "MainWindow" two levels up - but I am now confused what's difference between the two? Except how they are declared in "GrandChild". I want to add that both use "RegisterRoutedEvent" but RoutedEvent has a CLR wrapper

References:
http://weblogs.asp.net/vblasberg/archive/2010/03/30/wpf-routed-events-bubbling-several-layers-up.aspx
http://chuckhays.net/blog/2010/05/21/very-simple-routed-event-example/comment-page-1/#comment-1021
http://en.csharp-online.net/WPF_Concepts%E2%80%94Routed_Events_in_Action

MainWindow - Top Level
<window x:class="RoutedEventDemo.MainWindow"
="" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:RoutedEventDemo" title="MainWindow" height="350" width="525" background="DimGray" local:grandchild.grandchildroutedevclick="GrandChild_GrandChildRoutedEvClick">
<stackpanel local:grandchild.grandchildattachedevclick="GrandChildAttachedEvClickHandler">
<Label>Main Window</Label>
<local:middlechild>



public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void GrandChild_GrandChildRoutedEvClick(object sender, RoutedEventArgs e)
{
string Message = "MainWindow - GrandChildRoutedEvClickEvent handler - Source=" + Convert.ToString(e.Source);
MessageBox.Show(Message);
e.Handled = false;
return;
}

private void GrandChildAttachedEvClickHandler(object sender, RoutedEventArgs e)
{
string Message = "MainWindow - GrandChildAttachedEvClickHandler - Source=" + Convert.ToString(e.Source);
MessageBox.Show(Message);
return;
}
}

MiddleChild - 2nd Level
<usercontrol x:class="RoutedEventDemo.MiddleChild"
="" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlnsBig Grin | :-D ="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:RoutedEventDemo" mc:ignorable="d" background="DarkGray" d:designheight="300" d:designwidth="300">
<stackpanel>
<Label>MiddleChild</Label>
<local:grandchild x:name="Junior" verticalalignment="Stretch" grandchildroutedevclick="GrandChild_GrandChildRoutedEvClick">



public partial class MiddleChild : UserControl
{
public MiddleChild()
{
InitializeComponent();
}

private void GrandChild_GrandChildRoutedEvClick(object sender, RoutedEventArgs e)
{
string Message = "MiddleChild - GrandChildRoutedEvClickEvent handler - Source=" + Convert.ToString(e.Source);
MessageBox.Show(Message);
e.Handled = true; // set to true and MainWindow handler won't be triggered
return;
}
}

GrandChild - bottom level
<usercontrol x:class="RoutedEventDemo.GrandChild"
="" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlnsBig Grin | :-D ="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" background="LightGray" d:designheight="300" d:designwidth="300">
<stackpanel>
<Label>GrandChild</Label>
<Button Name="btnGrandChild" Click="btnGrandChild_Click_1">Button from GrandChild</Button>



public partial class GrandChild : UserControl
{
#region Routed Event
public static readonly RoutedEvent GrandChildRoutedEvClickEvent = EventManager.RegisterRoutedEvent("GrandChildRoutedEvClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(GrandChild));

// Provide CLR accessors for the event
public event RoutedEventHandler GrandChildRoutedEvClick
{
add { AddHandler(GrandChildRoutedEvClickEvent, value); }
remove { RemoveHandler(GrandChildRoutedEvClickEvent, value); }
}
#endregion

#region Attached Event
public static readonly RoutedEvent GrandChildAttachedEvClickEvent =
EventManager.RegisterRoutedEvent("GrandChildAttachedEvClick",
RoutingStrategy.Bubble,
typeof(RoutedEventHandler),
typeof(GrandChild));

public static void AddGrandChildAttachedEvClickHandler(DependencyObject o, RoutedEventHandler handler)
{
((UIElement)o).AddHandler(GrandChild.GrandChildAttachedEvClickEvent, handler);
}
public static void RemoveGrandChildAttachedEvClickHandler(DependencyObject o, RoutedEventHandler handler)
{
((UIElement)o).RemoveHandler(GrandChild.GrandChildAttachedEvClickEvent, handler);
}
#endregion

public GrandChild()
{
InitializeComponent();
}

private void btnGrandChild_Click_1(object sender, RoutedEventArgs e)
{
this.RaiseEvent(new RoutedEventArgs(GrandChildRoutedEvClickEvent, this));
this.RaiseEvent(new RoutedEventArgs(GrandChildAttachedEvClickEvent, this));
return;
}
}
dev


modified 10-Jan-13 2:24am.

QuestionHow to play an Audio File After another has Finished in WPF MediaElement Pin
Vimalsoft(Pty) Ltd4-Jan-13 3:58
professionalVimalsoft(Pty) Ltd4-Jan-13 3:58 
AnswerRe: How to play an Audio File After another has Finished in WPF MediaElement Pin
Pete O'Hanlon4-Jan-13 4:13
mvePete O'Hanlon4-Jan-13 4:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.