我正在尝试Click
为 a 中的按钮捕获事件,ResourceDictionary
但出现错误:
'WpfApplication1.MyResourceDictionary' does not contain a definition for 'GetTemplateChild' and no extension method 'GetTemplateChild' accepting a first argument of type 'WpfApplication1.MyResourceDictionary' could be found (are you missing a using directive or an assembly reference?)
MyResourceDictionay.xaml.cs 如下所示:
namespace WindowsApplication1
{
partial class MyResourceDictionary
{
public virtual void OnApplyTemplate()
{
Button myButton = this.GetTemplateChild("Crap") as Button;
}
}
}
MyResourceDictionay.xaml 如下所示:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WindowsApplication1.MyResourceDictionary"
x:ClassModifier="public">
<ControlTemplate x:Key="ExpandablePropertyEditorTemplate">
<Button x:Name="Crap" Foreground="White" Background="White">
<Image Source="Controls\check.png"/>
</Button>
</ControlTemplate>
</ResourceDictionary>
有什么帮助吗?