1

I am building a quiz redistributable desktop application. Questions can be text or image or both. Someone suggested i build a text and image dynamic user control to display the questions. I have searched all round but cant find any tutorial that shows how to build such user control.

i was reffered to 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 but it dosent help

Precious Okwu
  • 397
  • 5
  • 12

1 Answers1

1

As I can understand you need some control that can display a dynamic content (text/image). I can suggest you to use the content control that selects its content DataTemplate according to it's current data context. I'will put a whole solution in several minutes.

        <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>

Regards

Ilan
  • 2,762
  • 1
  • 13
  • 24