トップ回答者
EventHandlerの依存関係プロパティについて

質問
回答
-
簡単にするならbuttonという名前のButtonのFieldModifierをpublicにすればbuttonという名前のパブリックフィールドができます。
<UserControl x:Class="WpfApplication1.UserControl1" 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" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <Button x:Name="button" x:FieldModifier="public" /> </Grid> </UserControl>
あるいはUserControlがイベントとして内側のボタンに登録してやればいいです。public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } public event RoutedEventHandler ButtonClick { add { this.button.Click += value; //buttonという名前のボタンが定義されているとして } remove { this.button.Click -= value; } } }
個別に明示されていない限りgekkaがフォーラムに投稿したコードにはフォーラム使用条件に基づき「MICROSOFT LIMITED PUBLIC LICENSE」が適用されます。(かなり自由に使ってOK!)
- 回答としてマーク しん11111111 2016年7月16日 8:50
すべての返信
-
普通のイベントでもXAMLでイベントハンドラを結びつけることができます。正確にはコマンドを使用しますのでイベントハンドラではないですが・・・
例えば、以下を参考にしてみて下さい。コントロールの任意のイベントとコマンド xaml上で関連付ける
http://www.pine4.net/Memo/Article/Archives/417#Visual Studio 2015だと、System.Windows.Interactivity.dllを使うためにExpression Blend SDK のダウンロードとインストールを行う必要が無く、最初から同梱されていたような気もします。うろ覚えで申し訳ないです。
★良い回答には回答済みマークを付けよう! MVP - .NET http://d.hatena.ne.jp/trapemiya/
-
簡単にするならbuttonという名前のButtonのFieldModifierをpublicにすればbuttonという名前のパブリックフィールドができます。
<UserControl x:Class="WpfApplication1.UserControl1" 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" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <Button x:Name="button" x:FieldModifier="public" /> </Grid> </UserControl>
あるいはUserControlがイベントとして内側のボタンに登録してやればいいです。public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } public event RoutedEventHandler ButtonClick { add { this.button.Click += value; //buttonという名前のボタンが定義されているとして } remove { this.button.Click -= value; } } }
個別に明示されていない限りgekkaがフォーラムに投稿したコードにはフォーラム使用条件に基づき「MICROSOFT LIMITED PUBLIC LICENSE」が適用されます。(かなり自由に使ってOK!)
- 回答としてマーク しん11111111 2016年7月16日 8:50