2012-03-14 19 views
0

私はユーザーコントロールを作成しました。私はそれらをスタックパネルにコーディングして追加しました。コンパイル時にエラーはありません。しかし、私はこのユーザーコントロールのコンテンツとイメージを見ていませんでした。ボタンをクリックすると、別のページが開きます。私はクリックイベントが正常に動作していることを知っています。誰かが私に問題を解決する方法を教えてくれますか?前もって感謝します。 次は私のUserControl.xamlです:ユーザーコントロールのコンテンツとイメージが表示されません

<UserControl x:Name="NoButtonListItemControl" 
x:Class="PhoneApp1.NobuttonListItem" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup- 
compatibility/2006" 
mc:Ignorable="d" 
FontFamily="{StaticResource PhoneFontFamilyNormal}" 
FontSize="{StaticResource PhoneFontSizeNormal}" 
Foreground="{StaticResource PhoneForegroundBrush}" 
d:DesignHeight="480" d:DesignWidth="480"> 

<Grid x:Name="LayoutRoot" > 
    <StackPanel Margin="14,17,20,48" >    
      <Image Source="{Binding Path=PicFileName,  
       ElementName=NoButtonListItemControl}"  
       Width="120" Height="120"></Image>    
      <Button Content="{Binding Path=Description, 
      ElementName=NoButtonListItemControl }" 
         ClickMode="Press"  
      Click="btnNoButtonListItem_Click" FontFamily="Georgia" 
     FontSize="15" Foreground="SkyBlue" Height="90" 
     Width="400" /> 
     <TextBlock Text="{Binding Path=ID, 
     ElementName=NoButtonListItemControl }" 
      Style="{StaticResource pageTitleStyle}" 
         TextAlignment="{Binding}"  /> 

    </StackPanel> 
</Grid> 

次は私のUserControl.xaml.csです:

namespace PhoneApp1 
{ 
    public partial class NobuttonListItem : UserControl 
    { 
    public NobuttonListItem() 
    { 
     InitializeComponent(); 
    } 

    public static DependencyProperty PicFileNameProperty = 
    DependencyProperty.Register("PicFileName", typeof(string), 
    typeof(NobuttonListItem), null); 

    public static DependencyProperty DescriptionProperty = 
     DependencyProperty.Register("Description", typeof(string), 
    typeof(NobuttonListItem), null); 

    public static DependencyProperty IDProperty = 
     DependencyProperty.Register("ID", typeof(string), 
    typeof(NobuttonListItem), null); 

    public string PicFileName 
    { 
     get 
     { 
      return (string)GetValue(PicFileNameProperty); 
     } 
     set 
     { 
      SetValue(PicFileNameProperty, value); 
     } 
    } 

    public string Description 
    { 
     get 
     { 
      return (string)GetValue(DescriptionProperty); 
     } 
     set 
     { 
      SetValue(DescriptionProperty, value); 
     } 
    } 

    public string ID 
    { 
     get 
     { 
      return (string)GetValue(IDProperty); 
     } 
     set 
     { 
      SetValue(IDProperty, value); 
     } 
    } 

    private void btnNoButtonListItem_Click(object sender, 
     RoutedEventArgs e) 
    { 
     App.Navigate(new 
     Uri(String.Format("/CallPage.xaml?ID={0}",ID), 
     UriKind.Relative)); 
    } 


    } 

}

test.xamlページがあります私はユーザーコントロールを追加しました:

<phone:PhoneApplicationPage xmlns:my="clr- 
    namespace:PhoneApp1" 
    x:Class="PhoneApp1.test" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:phone="clr- 
    namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
    xmlns:shell="clr- 
    namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup- 
    compatibility/2006" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    SupportedOrientations="Portrait" Orientation="Portrait" 
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" 
    shell:SystemTray.IsVisible="True"> 


<Grid x:Name="LayoutRoot" Background="Transparent"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="*"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 


    <StackPanel x:Name="TitlePanel" Grid.Row="0" 
     Margin="12,17,0,28"> 
     <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" 
      Style="{StaticResource PhoneTextNormalStyle}"/> 
     <TextBlock x:Name="PageTitle" Text="page name" Margin="9,- 
     7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> 
    </StackPanel> 

    <StackPanel x:Name="spListPanel" Loaded="spListPanel_Loaded" 
    Grid.Row="1" Margin="12,0,12,0"> 

    </StackPanel> 

    <Grid Grid.Row="2" Margin="12,0,12,0"> 
     <StackPanel> 

     </StackPanel> 
    </Grid> 

    </Grid> 



</phone:PhoneApplicationPage> 

test.xamのLページの背後にあるコード:

namespace PhoneApp1 
    { 
    public partial class test : PhoneApplicationPage 
    { 
     public test() 
     { 
     InitializeComponent();    
     this.Loaded += new RoutedEventHandler(Page_Loaded); 

     } 

     void Page_Loaded(object sender, RoutedEventArgs e) 
    { 


     ShowList(); 

    } 
    void ShowList() 
    { 
     int userControlUniqueID = 0; 

     AddItem("1", "Test 1", "onHold_icon.png", 1); 
     AddItem("2", "Test 2", "responded_icon.png",2); 

    } 


    void AddItem(string id, string description, string fileName, 
     int userControlUniqueID) 
    { 
     NobuttonListItem item = new NobuttonListItem(); 
     item.Name = "lst_" + Convert.ToString(userControlUniqueID); 
     item.ID = id; 
     item.Description = description; 
     item.PicFileName = "/images" + "/" +fileName; 
     spListPanel.Children.Add(item); 

    } 
    } 
} 
+0

アプリケーションを実行し、バインディングエラーの出力ウィンドウを確認してください...私は確信していませんが、これはイメージをバインドする文字列へのSourceプロパティタイプ値... –

答えて

0

それはまだdoesnの場合は、あなたの "分離コード" ファイル

this.DataContext = this; 

に次のコードを追加することを忘れないでください」 t作業、出力ウィンドウに出力の一部を投稿してください

+0

私はthis.DataContext = thisを配置した場合; "ShowList fuction"と呼ぶことができます。出力はtxtUserは私の独立したストアのプロパティです。 this.spListPanel.DataContext = thisに変更した場合、これのメンバーにはコントロールであるbase、_contentLoaded、ApplicationTile、LayourRoot、PageTitle、spListPanel、TitlePanelが含まれます。私はまだ私のqueoteで何が間違っているのか分からない。 – user819774

+0

ショーリスト機能の前に配置してください this.spListPanel.ItemsSource = myObservableCollection ; – ry8806

関連する問題