Basic idea which I had was to create one button with which I will fill TreeView over XML or MySQL. Problem is that idea which I had was not so simple to implement, because probably can not just "fill" on click tree, but I have to bind... I guess is that I would need to create class for MySQL and over Autofac to update class responsible for binding treeview. Since I need that piece of code to understand autofac better, I will write it here.
First what I did is to implement interface of all interfaces :) that means that this interface will be later used for actual implementation:
public interface IRead
{
List<string> Read();
}
Then I implemented IReadAndCreateTree like:
public interface IReadAndCreateTree
{
List<string> ReadXML();
}
Then model where "all things come together":
public class XmlTreeReader : IReadAndCreateTree
{
private IRead _reader;
public XmlTreeReader(IRead reader)
{
_reader = reader;
}
public List<string> ReadXML()
{
return this._reader.Read();
}
}
Now model which I will use for my XAML:
public class XmlTreeReader : IReadAndCreateTree
{
private IRead _reader;
public XmlTreeReader(IRead reader)
{
_reader = reader;
}
public List<string> ReadXML()
{
return this._reader.Read();
}
}
On the end XAML:
<Window x:Class="AutofacTreeView.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewModel="clr-namespace:AutofacTreeView.ViewModel"
xmlns:model="clr-namespace:AutofacTreeView.Model"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<StackPanel.Resources>
<viewModel:LoadXMLClick x:Key="LoadXMLClick"/>
<model:TreeViewModel x:Key="TreeViewModel"/>
</StackPanel.Resources>
<TreeView x:Name="tvAutofac" DataContext="{StaticResource TreeViewModel}" ItemsSource="{Binding Path=TreeViewModels}" Height="205"/>
<Button DataContext="{StaticResource LoadXMLClick}" Content="Load XML" Command="{Binding LoadXmlClickCommand}"/>
</StackPanel>
</Grid>
</Window>
I hope this is all