I trying to create a UserControl that will be added a variable number of times to a wpf window at run-time. This is my first attempt at a UserControl. I have two requirements for this UserControl:
The content of the label is to be defined at run-time.
The StackPanel should respond to a click event at run-time.
Here is my XAML:
<UserControl
x:Class="CalendarDay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="150"
d:DesignWidth="100">
<Border
BorderThickness="1"
BorderBrush="Gray">
<DockPanel>
<StackPanel
DockPanel.Dock="Top"
Orientation="Horizontal">
<Label
x:Name="lblTopic"
FontSize="16"
FontWeight="DemiBold"
HorizontalAlignment="Left">
</Label>
</StackPanel>
</DockPanel>
</Border>
</UserControl>
My specific questions are:
How to expose the Content property of the label so it can be set at run-time? This value will not change for the lifetime of the control nor will it be changeable by the user.
How to expose the MouseLeftButtonUp Event of the StackPanel.
Thanks in advance.