2016-05-08 7 views
0

Controls/Templatesのイベントを書き込む方法は、ResourceDictionaryで定義されていますか?リソースディクショナリ内のコントロールのイベントハンドラを書き込む

今のところ私はevent to command strategyを使用し、ViewModels(DataContext)にはすべてeventCommandsと書いています。

public partial class ResourceDictionary 
{ 
    //... 
} 

をしてclassように指定する必要があります。このため

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 

       > 

<Style TargetType="{x:Type TextBox}" x:Key="MyTextBox"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate> 
       <TextBox Width="500" Background="LightGreen" TextChanged="TextChanged" /> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

答えて

0

は、我々はx:classを使用してResourceDictionaryためのクラスファイルを記述する必要があります:私はTextChangedイベントResourceDictionaryに書くことができますどのようにコードの下を参照してください。 in ResourceDictionary

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        x:Class="YourNamespace.ResourceDictionary" 
        > 

    <Style TargetType="{x:Type TextBox}" x:Key="MyTextBox"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate> 
        <TextBox Width="500" Background="LightGreen" TextChanged="TextChanged" /> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
関連する問題