I'm using MahApps for my first Wpf project, and more specifically tabControls. I tested it on a tiny test project. It worked well, until I tried to merge my code in my project.
Here's an example of my code behind :
public class Datas
{
public ObservableCollection<string> titles { get; set; }
public Datas()
{
init();
}
public void init()
{
titles = new ObservableCollection<string>()
{
"Title 1",
"Title 2",
"Title 3",
"Title 4"
};
}
}
public partial class Window1 : MetroWindow
{
private Datas datas;
public Window1()
{
init();
}
private void init()
{
datas = new Datas();
this.DataContext = this;
}
}
And my Xaml code :
<TabControl DataContext="{Binding Datas}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding titles}"/>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<TextBlock Text="Content" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
I've been searching for few days so far. I've found a topic about dataBinding to another class but it doesn't seem to work for me. Not sure if I can use both DataContexts in my Window1 class, even if I tried something like binding multiple controls to different dataContexts.
Do I really need something like that ? It seems to be bigger than what I need but I may be wrong. So, my problem is that I would like to have my tabs whose titles are those in my list, and it doesn't display anything (no error when running though).
Thanks for your help, and please be slow in your answers, I'm still new to Wpf :)