My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
SILVERLIGHT CODE EXAMPLE created on Tuesday, June 15, 2010 permalink
How to make a class that renders an interactive FrameworkElement and interacts with the View
This example shows a class (Flashcard) which you can instantiate as many times as you want, rendering each as a StackPanel which you attach to another StackPanel, all of the interactivity in each control remains intact (showing the back of the flashcard on mouseover). Each flashcard also has an event which the main View is able to react to (counting how many times a flashcard is turned over).
XAML:
<UserControl x:Class="TestControl2222.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <StackPanel Margin="10">

    <StackPanel Margin="0 0 0 20" Orientation="Horizontal">
        <TextBlock Text="The number of times you turned over a flashcard: "/>
        <TextBlock Text="{Binding NumberOfTimesUserTurnedOverAFlashcard}"/>
    </StackPanel>

    <ContentControl Content="{Binding MainContent}"/>

    </StackPanel>
</UserControl>

Code Behind:
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System;

namespace TestControl2222
{
    public partial class MainPage : UserControl, INotifyPropertyChanged
    {
        #region ViewModelProperty: MainContent
        private object _mainContent;
        public object MainContent
        {
            get
            {
                return _mainContent;
            }

            set
            {
                _mainContent = value;
                OnPropertyChanged("MainContent");
            }
        }
        #endregion .

        #region ViewModelProperty: NumberOfTimesUserTurnedOverAFlashcard
        private int _numberOfTimesUserTurnedOverAFlashcard;
        public int NumberOfTimesUserTurnedOverAFlashcard
        {
            get
            {
                return _numberOfTimesUserTurnedOverAFlashcard;
            }

            set
            {
                _numberOfTimesUserTurnedOverAFlashcard = value;
                OnPropertyChanged("NumberOfTimesUserTurnedOverAFlashcard");
            }
        }
        #endregion .

        private StackPanel _spMain = new StackPanel();
        private List<Flashcard> _flashcards = new List<Flashcard>();

        private TextBlock _tbFront = new TextBlock();
        private TextBlock _tbBack = new TextBlock();

        public MainPage()
        {
            InitializeComponent();
            DataContext = this;
            NumberOfTimesUserTurnedOverAFlashcard = 0;

            _spMain.HorizontalAlignment = HorizontalAlignment.Left;

            _flashcards.Add(new Flashcard("What color is the sky?", "blue"));
            _flashcards.Add(new Flashcard("What color is the sun?", "yellow"));
            _flashcards.Add(new Flashcard("What color if grass?", "green"));

            foreach (var flashcard in _flashcards)
            {
                _spMain.Children.Add(flashcard.RenderControl());
                flashcard.OnLookedAtFlashcard += new EventHandler(flashcard_OnLookedAtFlashcard);
            }

            MainContent = _spMain;
        }

        void flashcard_OnLookedAtFlashcard(object sender, EventArgs e)
        {
            NumberOfTimesUserTurnedOverAFlashcard++;
        }

        void _tbFront_MouseEnter(object sender, MouseEventArgs e)
        {
            _tbFront.Foreground = new SolidColorBrush(Colors.LightGray);
            _tbBack.Visibility = Visibility.Visible;
        }

        void _tbFront_MouseLeave(object sender, MouseEventArgs e)
        {
            _tbFront.Foreground = new SolidColorBrush(Colors.Black);
            _tbBack.Visibility = Visibility.Collapsed;
        }

        #region INotifiedProperty Block
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion .
    }

    public class Flashcard
    {
        private string _front;
        private string _back;
        private TextBlock _tbFront = new TextBlock();
        private TextBlock _tbBack = new TextBlock();

        public event EventHandler OnLookedAtFlashcard;

        public Flashcard(string front, string back)
        {
            _front = front;
            _back = back;
        }

        public FrameworkElement RenderControl()
        {
            StackPanel spMain = new StackPanel();
            spMain.Margin = new Thickness { Bottom = 10 };

            _tbFront.Text = _front;
            spMain.Children.Add(_tbFront);
            _tbFront.MouseEnter += new MouseEventHandler(_tbFront_MouseEnter);
            _tbFront.MouseLeave += new MouseEventHandler(_tbFront_MouseLeave);

            _tbBack.Text = _back;
            _tbBack.Opacity = 0;
            _tbBack.FontWeight = FontWeights.Bold;
            spMain.Children.Add(_tbBack);

            return spMain;
        }

        void _tbFront_MouseEnter(object sender, MouseEventArgs e)
        {
            _tbFront.Foreground = new SolidColorBrush(Colors.Gray);
            _tbBack.Opacity = 100;
            if (OnLookedAtFlashcard != null)
                OnLookedAtFlashcard(this, null);
        }

        void _tbFront_MouseLeave(object sender, MouseEventArgs e)
        {
            _tbFront.Foreground = new SolidColorBrush(Colors.Black);
            _tbBack.Opacity = 0;
        }
    }
}
need markup?