构建UserControl来动态显示文本和图像
本文关键字:图像 文本 动态显示 UserControl 构建 | 更新日期: 2023-09-27 18:17:38
我正在构建一个可重新分发的测试桌面应用程序。问题可以是文本或图像,也可以两者都有。有人建议我建立一个文本和图像动态用户控件来显示问题。我到处搜索,但找不到任何教程,显示如何建立这样的用户控制。
参考http://www.akadia.com/services/dotnet_user_controls.html,http://en.csharp-online.net/Create_List_Controls,https://msdn.microsoft.com/en-us/library/aa302342.aspx但是它没有帮助
正如我所理解的,您需要一些可以显示动态内容(文本/图像)的控件。我可以建议您使用根据其当前数据上下文选择其内容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>
对