开发者

WPF Event Passing Between two child usercontrol of a main usercontrol

I am using Visual Studio 2010. I have two custom usercontrol class in wpf. And there is a Main Usercontrol class named MainWindow.xaml. I have added two Different class named ListTreeviewContentPane.xaml and ToolBarMenuContentPane.xaml. In the MainWindow.xaml i have added them using this type of code-

<local:ListTreeViewContentPane x:Name="usertreeview"></local:ListTreeViewContentPane>
<local:ToolBarMenuContentPane x:Name="usertoolbar"></local:ToolBarMenuContentPane>开发者_StackOverflow社区

I want to click in usertreeview and for this run a code in usertoolbar. But the problem is usertreeview has no concept of usertoolbar instance. I have done this using delegate and event. But as because they are child of Mainwindow. Is it possible to create an action in usertreeview and catch it or write the handler in usertoolbar or make change in usertoolbar without using delegate and event binding?

or is it possible - click in the usertreeview and make change in usertoolbar as they both are the child of mainwindow without using delegate?


Using Interaction from the Blend SDK you can do trigger on events in other controls and invoke methods which sounds like it would fit your problem, e.g.

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
<TextBox>
    <i:Interaction.Triggers>
        <i:EventTrigger SourceName="buton" EventName="Click">
            <ei:CallMethodAction MethodName="Clear" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</TextBox>
<Button Name="buton" Content="Clear Text" />

If the Button is clicked the trigger in the TextBox is fired and the method Clear on the TextBox is called, clearing the text.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜