【问题标题】:Resource Dictionary raises exceptions when calling a method located in MainPage调用位于 MainPage 中的方法时,资源字典引发异常
【发布时间】:2012-04-18 05:40:38
【问题描述】:

在 windows phone 7.1 项目中:

我的资源字典如下所示:

    <DataTemplate x:Name="ItemsTemplate">
            ...
            <StackPanel VerticalAlignment="Top"
                        ManipulationStarted="ManipulationStarted" 
                        ManipulationCompleted="ManipulationCompleted">
                <TextBlock Text="{Binding ItemDescription}" FontSize="32" Foreground="#FF3B3B3B"  Margin="5,0,0,0" FontWeight="Bold" />
                <TextBlock Text="{Binding List.ListName}" FontSize="20" Foreground="DarkMagenta" Margin="5,0,0,0" FontWeight="Bold"/>
            </StackPanel>
        </StackPanel>
    </DataTemplate>

ManipulationStarted() 和 ManipulationCompleted() 函数位于 MainPage.xaml.cs 中,通过 MainPage.xaml 使用以下代码引用 DataTemplate:

<toolkit:LongListSelector x:Name="ListSelector" 
     ItemTemplate="{StaticResource ItemsTemplate}" 
     ItemsSource="{Binding Items}">
</toolkit:LongListSelector>

当我尝试在列表中添加项目时出现异常。

如果我将 DataTemplate 放在 MainPage.xaml 中,一切正常。

我知道问题出在函数引用上,但我想首先知道为什么无法通过资源字典找到函数,以及是否有适当的方法来执行此操作或通过任何技巧来克服此问题.

【问题讨论】:

  • App.Application_UnhandledException(object sender, System.Windows.ApplicationUnhandledExceptionEventArgs e) Line 150 + 0x5 bytes C# {"Unspecified error"}

标签: c# windows-phone-7 xaml resourcedictionary


【解决方案1】:

问题在于事件接线。 App 级别没有相应的事件处理程序,但我猜在页面级别有。

【讨论】:

  • 没发现,我说你明白了!
  • 但是资源字典不是像图书馆那样链接在“页面”上吗?我的意思是我们使用#includes (c) 或使用 on (c#) ??有什么解决方法吗?
【解决方案2】:

您不应该在DataTemplate 上使用x:Key 而不是x:Name 吗?

【讨论】:

  • 没有任何区别..当我试图找到一种方法来完成这项工作时,我改变了它!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-07
  • 2019-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多