2015-10-14 56 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