Is it possible to include an event handler reference in a data template that is not associated with the code-behind where the event handler is defined? I'm getting a PARSER-BAD-PROPERTY-VALUE when trying to pull this off.
是否可以在数据模板中包含事件处理程序引用,该数据模板与定义事件处理程序的代码隐藏无关?当我试图把它拉下来时,我得到了一个PARSER-BAD-PROPERTY-VALUE。
For example, let's say I have this very simple XAML.
例如,假设我有这个非常简单的XAML。
page.xaml
page.xaml
<DataTemplate x:Key="ItemsTemplate">
<HyperlinkButton Click="HyperlinkButton_Click" />
</DataTemplate>
<ItemsControl ItemTemplate="{StaticResource ItemsTemplate}" />
This works fine since the event handler HyperlinkButton_Click is in the code-behind for page.xaml.
这很好用,因为事件处理程序HyperlinkButton_Click位于page.xaml的代码隐藏中。
BUT ... when I move the data template to another file ...
但是......当我将数据模板移动到另一个文件时......
resources.xaml
resources.xaml
<DataTemplate x:Key="ItemsTemplate">
<HyperlinkButton Click="HyperlinkButton_Click" />
</DataTemplate>
page.xaml
page.xaml
<ItemsControl ItemTemplate="{StaticResource ItemsTemplate}" />
... Silverlight seems to lose track of what I'm doing and I get the PARSER-BAD-PROPERTY-VALUE error.
... Silverlight似乎忘记了我正在做的事情,我得到了PARSER-BAD-PROPERTY-VALUE错误。
1 个解决方案
#1
0
I know you can not dynamically add controls that have event handlers, like in (XamlReader.Load(<"Button Click="handler".../>)). So maybe that's the reason why the Click in the external file does not work.
我知道你不能动态添加具有事件处理程序的控件,例如(XamlReader.Load(<“Button Click =”handler“... />))。所以也许这就是为什么外部文件中的Click不会工作。
#1
0
I know you can not dynamically add controls that have event handlers, like in (XamlReader.Load(<"Button Click="handler".../>)). So maybe that's the reason why the Click in the external file does not work.
我知道你不能动态添加具有事件处理程序的控件,例如(XamlReader.Load(<“Button Click =”handler“... />))。所以也许这就是为什么外部文件中的Click不会工作。