2015-10-14 57 views
1

我正在構建測驗可重新發布的桌面應用程序。問題可以是文字或圖片或兩者兼而有之。 有人建議我建立一個文本和圖像動態用戶控件來顯示問題。我已經全面搜索,但無法找到任何教程,顯示如何建立這樣的用戶控制。構建UserControl以動態顯示文本和圖像

我在下文稱到http://www.akadia.com/services/dotnet_user_controls.htmlhttp://en.csharp-online.net/Create_List_Controls,https://msdn.microsoft.com/en-us/library/aa302342.aspx 但它dosent幫助

回答

1

至於我能理解你需要一些控制,可以顯示動態內容(文本/圖片)。我可以建議你使用內容控件,根據當前的數據上下文選擇其內容DataTemplate。 我會在幾分鐘內提出一個完整的解決方案。

 <ContentControl Content="{Binding CurrentControlContent.Content}"> 
      <ContentControl.Resources> 
       <DataTemplate DataType="{x:Type soSandBoxListView:SingleTextModel}"> 
        <TextBlock Text="{Binding SingleModelContent}" Background="Tan"></TextBlock> 
       </DataTemplate> 
       <DataTemplate DataType="{x:Type soSandBoxListView:MultipleTextModel}"> 
        <StackPanel> 
         <TextBlock Text="{Binding FirstName}" Background="Yellow"></TextBlock> 
         <TextBlock Text="{Binding LastName}" Background="Red"></TextBlock> 
         <!--use the binding to your picture presentation in model--> 
         <Image Source="Resources/yotveta.jpg" Stretch="None"></Image> 
        </StackPanel> 
       </DataTemplate> 
      </ContentControl.Resources> 
     </ContentControl> 

問候

+0

非常感謝您的回答,先生。這可以使用Windows窗體完成嗎? –

+0

@OkwuPrecious嗨,我確定在winforms中有這樣做的能力,但我無法幫助你。對不起;)。 – Ilan