【问题标题】:Build UserControl to display both text and image dynamically构建 UserControl 以动态显示文本和图像
【发布时间】:2016-01-12 21:09:47
【问题描述】:

我正在构建一个测验可再发行桌面应用程序。问题可以是文本或图像或两者兼而有之。 有人建议我构建一个文本和图像动态用户控件来显示问题。我进行了全面搜索,但找不到任何说明如何构建此类用户控件的教程。

我被推荐给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 但它没有帮助

【问题讨论】:

    标签: c# wpf user-controls desktop-application


    【解决方案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>
    

    问候

    【讨论】:

    • 非常感谢您的回答先生。这可以使用 Windows 窗体完成吗?
    • @OkwuPrecious 嗨,我确信在 winforms 中可以做到这一点,但我无法帮助你。对不起;)。
    猜你喜欢
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-29
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多