milosev.com
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
      • Italy2022
      • Côte d'Azur 2024
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home
  3. C#

Treeview with Autofac

Details
Written by: Stanko Milosev
Category: WPF
Published: 30 November -0001
Last Updated: 17 February 2014
Hits: 1785

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

IsNullOrEmpty

Details
Written by: Stanko Milosev
Category: Beginning
Published: 11 February 2013
Last Updated: 11 February 2013
Hits: 5264

If varible is string, then to check if it is null use:

if (containerid.IsNullOrEmpty())
{ containerid = "-1"; }

Or String.IsNullOrEmpty()

Because null is not empty...

Unsafe code may only appear if compiling with /unsafe

Details
Written by: Stanko Milosev
Category: Beginning
Published: 16 August 2008
Last Updated: 05 November 2009
Hits: 7836

In VS.NET go to the project property page and in configuration properties>build set Allow Unsafe Code Blocks to True.


Taken from here.

Example of WebClient

Details
Written by: Stanko Milosev
Category: Code snippets
Published: 21 December 2019
Last Updated: 10 February 2022
Hits: 2836
Just a small example of WebClient:
string milosevCom = "http://www.milosev.com";
string doc = "";
using (System.Net.WebClient client = new System.Net.WebClient())
{
	doc = client.DownloadString(milosevCom);
}

Console.WriteLine(doc);
Console.ReadKey();
WebClient is from .NET 6 obsolete.
  1. Selenium in Mono under Ubuntu
  2. Selenium in .NET
  3. Execute sql scripts from console
  4. OCR with MODI

Subcategories

WPF

Beginning

Code snippets

NUnit

LINQ

Windows Forms

Page 34 of 39

  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38