2016-09-07 52 views
1

我想将我的XAML ViewCell与c#对应关联起来,并将它与listview一起使用。 WeatherCell.xamlViewcell XAML + CS抛出构建动作'Page'不受支持错误

<?xml version="1.0" encoding="utf-8" ?> 
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Name="cell" 
      x:Class="UI.WeatherCell"> 

    <ViewCell.View> 
    <StackLayout Orientation="Vertical" Padding="10"> 

     <Label Text="WeatherCell" 
      x:Name="TempLabel" 
       VerticalOptions="Center" 
       HorizontalOptions="Center" /> 

     <Label Text="WeatherCell" 
      x:Name="LocationLabel" 
       VerticalOptions="Center" 
       HorizontalOptions="Center" /> 

    </StackLayout> 
    </ViewCell.View> 

</ViewCell > 

WeatherCell.cs

namespace UI 
{ 
    public partial class WeatherCell : ViewCell 
    { 
     public WeatherCell() 
     { 
      InitializeComponent(); 
     } 
    } 
} 

在MainPage.cs简称如下

this.WeatherListView.ItemsSource = Weather.Weather.DataFactory.genForecast(); 
this.WeatherListView.ItemTemplate = new DataTemplate(typeof(WeatherCell)); 

在建设,我得到错误的

'Page' is not supported by the specific combination of the project's targets. \WeatherCell.xaml. 

我guesss w ^作为x:Class =“UI.WeatherCell”将链接xaml和cs。我究竟做错了什么?

回答

1

更改WeatherCell.xaml的构建操作可解决该问题。

它必须被设置为EmbeddedResource

生成操作属性可以在文件属性的上下文菜单中找到。

0

右键单击xaml文件,然后单击属性。 在属性下选择Embedded Resource。 重建您的项目。

相关问题