2011-08-10 38 views
-1

爲什麼下面的C#代碼不能生成與我的Silverlight代碼相同的代碼?C#代碼中的錯誤相當於Silverlight xaml

XAML

<Border CornerRadius="8" BorderBrush="White" Height="70" BorderThickness="4"> 
     <StackPanel Orientation="Horizontal"> 
      <Border Margin="5,0,0,0" BorderBrush="White" Height="45" Width="45" BorderThickness="2" CornerRadius="2" Background="White"> 
       <Image Source="/Crystal%20Cloud;component/Resources/Images/weapons/swords/sword_0.png" /> 
      </Border> 
      <StackPanel Margin="10,0,0,0"> 
       <TextBlock Text="Wooden Dagger" FontFamily="Comic Sans MS" /> 
       <TextBlock Text="DPS: 1" FontFamily="Comic Sans MS" FontSize="16" Margin="15,0,0,0" /> 
      </StackPanel> 
     </StackPanel> 
    </Border> 

C#

private Border CreateListItem(Item item) 
    { 
     // Main border 
     Border itemBorder = new Border(); 
     itemBorder.BorderThickness = new Thickness(4); 
     itemBorder.CornerRadius = new CornerRadius(8); 
     itemBorder.BorderBrush = new SolidColorBrush(Colors.White); 
     itemBorder.Height = 70; 

     // Main stack panel 
     StackPanel mainPanel = new StackPanel(); 
     mainPanel.Orientation = Orientation.Horizontal; 
     itemBorder.Child = mainPanel; 

     // The item's image border 
     Border imageBorder = new Border(); 
     imageBorder.Margin = new Thickness(5, 0, 0, 0); 
     itemBorder.BorderThickness = new Thickness(2); 
     itemBorder.CornerRadius = new CornerRadius(2); 
     itemBorder.BorderBrush = new SolidColorBrush(Colors.White); 
     itemBorder.Background = new SolidColorBrush(Colors.White); 
     itemBorder.Height = 45; 
     itemBorder.Width = 45; 
     mainPanel.Children.Add(imageBorder); 

     // The item's image 
     Image image = new Image(); 
     image.Source = new BitmapImage(new Uri("/Crystal%20Cloud;component/Resources/Images/weapons/swords/sword_0.png")); 
     imageBorder.Child = image; 

     // The stack panel for the text 
     StackPanel textPanel = new StackPanel(); 
     textPanel.Margin = new Thickness(10, 0, 0, 0); 
     mainPanel.Children.Add(textPanel); 

     // The title text block 
     TextBlock titleText = new TextBlock(); 
     titleText.Text = "Wooden Dagger"; 
     titleText.FontFamily = new FontFamily("Comic Sans MS"); 
     textPanel.Children.Add(titleText); 

     // The status text block 
     TextBlock statusText = new TextBlock(); 
     statusText.Text = "DPS: 1"; 
     statusText.FontFamily = new FontFamily("Comic Sans MS"); 
     statusText.FontSize = 16; 
     statusText.Margin = new Thickness(15, 0, 0, 0); 
     textPanel.Children.Add(statusText); 

     return itemBorder; 
    } 
+0

有什麼區別?其他人不做的是什麼? – Gabe

+0

結果有什麼不同? –

回答

0

爾格......剛剛發現itemBorder應改爲imageBorder的bug。