首页 新闻 搜索 专区 学院

Windows Phone自定义控件出错

0
悬赏园豆:10 [已关闭问题] 关闭于 2012-09-23 19:07

在一个小app上需要用到一个usercontrol,之前用WPF做了一个,用起来都正常,后来在Windows Phone上做一个时,调试时IDE报错

 

下面是部分代码

DependencyProperty

 1  public string City
 2         {
 3             get
 4             {
 5                 return (string)this.GetValue(CityProperty);
 6             }
 7             set
 8             {
 9                 SetValue(CityProperty, value);
10             }
11         }
12 
13         public static DependencyProperty CityProperty = DependencyProperty.Register("City", typeof(string), typeof(CitySummary), new PropertyMetadata("N/A"));

 

 1 public CitySummary()
 2         {
 3             InitializeComponent();
 4 
 5             Binding cityBind = new Binding();
 6             cityBind.Source = this;
 7             cityBind.Path = new PropertyPath(CitySummary.CityProperty);
 8             txtCity.SetBinding(TextBlock.TextProperty, cityBind);
 9 
10         }

 

 

UserControl的XAML

View Code
 1 <UserControl x:Class="NailClipper.Toolkits.CitySummary"
 2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 5     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 6     mc:Ignorable="d"
 7     FontFamily="{StaticResource PhoneFontFamilyNormal}"
 8     FontSize="{StaticResource PhoneFontSizeNormal}"
 9     Foreground="{StaticResource PhoneForegroundBrush}"
10     d:DesignHeight="170" d:DesignWidth="200">
11     
12     <Grid x:Name="LayoutRoot" >
13         <Grid.RowDefinitions>
14             <RowDefinition Height="114"/>
15             <RowDefinition Height="56"/>
16         </Grid.RowDefinitions>
17         <Canvas Background="Black" Opacity="0.15" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Grid.RowSpan="2">
18             
19         </Canvas>
20         <Grid Margin="0">
21             <Grid.ColumnDefinitions>
22                 <ColumnDefinition Width="87"/>
23                 <ColumnDefinition Width="113"/>
24             </Grid.ColumnDefinitions>
25             <TextBlock Name="txtCity"  VerticalAlignment="Top" Margin="10,12,0,0"  Foreground="{StaticResource PhoneForegroundBrush}" />
26             <Image Name="imgPath" Grid.Column="1" Margin="10,8,8,10"  />
27         </Grid>
28         <StackPanel Margin="0" Grid.Row="1">
29             <TextBlock Name="txtTemperature"  Margin="10,0,0,0" Foreground="{StaticResource PhoneForegroundBrush}" />
30             <TextBlock Name="txtCondition"  Margin="10,0,0,0" Foreground="{StaticResource PhoneForegroundBrush}" />
31         </StackPanel>
32     </Grid>
33 </UserControl>

 

 

页面调用UserControl  wpCityList是一个WrapPanel

View Code
 1             Thickness margin = new Thickness(0, 0, 5, 10);
 2             
 3             CitySummary city1 = new CitySummary { City = "长春", Temperature = "10°/15°", Condition = "多云", ImagePath = "/NailClipper.Weather;component/Images/多云D.png" };
 4             city1.Margin = margin;
 5             city1.MouseLeftButtonDown += new MouseButtonEventHandler(city1_MouseLeftButtonDown);
 6 
 7             CitySummary city2 = new CitySummary { City = "宿迁", Temperature = "25°/35°", Condition = "", ImagePath = "/NailClipper.Weather;component/Images/晴D.png" };
 8             city2.Margin = margin;
 9             city2.MouseLeftButtonDown += new MouseButtonEventHandler(city1_MouseLeftButtonDown);
10 
11             CitySummary city3 = new CitySummary { City = "北京", Temperature = "15°/25°", Condition = "小雨", ImagePath = "/NailClipper.Weather;component/Images/小雨D.png" };
12             city3.Margin = margin;
13             city3.MouseLeftButtonDown += new MouseButtonEventHandler(city1_MouseLeftButtonDown);
14 
15             
16             wpCityList.Children.Add(city1);
17             wpCityList.Children.Add(city2);
18             wpCityList.Children.Add(city3);

 

 

运行调试的时候就报错了,不知道怎么回事,求解~谢了各位

< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册