I am playing around with WPF and I cannot find out how to dynamically add multiple items to the Content. I need to have to TextBlocks and two images on a UserControl.
"MenuCount" and "MenuText" are two TextBlocks that are declared within the class and can be modified via properties.
The code I have so far is:
public MainPage() : base() { InitializeComponent(); DataContext = this;
MenuCount.Text = "1 of 100"; MenuCount.FontSize = 20; MenuCount.FontFamily = new System.Windows.Media.FontFamily("Courier"); MenuCount.Margin = new Thickness(500, 0, 0, 0); MenuCount.Foreground = this.FontColor;
MainContent = MenuText; MainContent = MenuCount; //This is where the code is incorrect, obviously. I need to have both of these items, and two images (not in the code yet) within this. } [/CODE]
Question
James Rose
Hello gang,
I am playing around with WPF and I cannot find out how to dynamically add multiple items to the Content. I need to have to TextBlocks and two images on a UserControl.
"MenuCount" and "MenuText" are two TextBlocks that are declared within the class and can be modified via properties.
The code I have so far is:
<UserControl x:Class="BediaMenu.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" mc:Ignorable="d" d:DesignHeight="55" d:DesignWidth="458">
<StackPanel HorizontalAlignment="Left" Margin="10">
<ContentControl Content="{Binding MainContent}"/>
</StackPanel>
</UserControl>
[/CODE]
Any thoughts?
Link to comment
Share on other sites
4 answers to this question
Recommended Posts