Application of the "C #" ADO. Net entities framework in the WPF TreeView

Source: Internet
Author: User

XAML Code

<window x:class= "Wpfapplication73.mainwindow"

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"

Xmlns:local= "Clr-namespace:wpfapplication73"

Mc:ignorable= "D"

Title= "MainWindow" height= "width=" 525 ">

<Grid>

<treeview itemssource= "{Binding}" >

<TreeView.Resources>

<textblock text= "{Binding year}"/>

</HierarchicalDataTemplate>

<stackpanel orientation= "Horizontal" >

<textblock text= "{Binding country}"/>

<textblock text= "{Binding date,stringformat=d}"/>

</StackPanel>

</HierarchicalDataTemplate>


<stackpanel orientation= "Horizontal" >

<textblock text= "{Binding Position}"/>

<textblock text= "{Binding Racer}"/>

</StackPanel>

</HierarchicalDataTemplate>

</TreeView.Resources>


</TreeView>

</Grid>

</Window>


Hide Code:

Using System;

Using System.Collections.Generic;

Using System.Linq;

Using System.Text;

Using System.Threading.Tasks;

Using System.Windows;

Using System.Windows.Controls;

Using System.Windows.Data;

Using System.Windows.Documents;

Using System.Windows.Input;

Using System.Windows.Media;

Using System.Windows.Media.Imaging;

Using System.Windows.Navigation;

Using System.Windows.Shapes;


Namespace WpfApplication73

{

<summary>

Interaction Logic for MainWindow.xaml

</summary>

public partial class Mainwindow:window

{

Public formula1v2entities data = new Formula1v2entities ();

Public MainWindow ()

{

InitializeComponent ();

This. DataContext = years;

}


Public ienumerable<class1> years

{

Get

{

F1datacontext.data = Data;

return data. Races.select (r = new Class1

{

Year = R.date.year

}). Distinct (). (c = c.year). ToList ();

Return (from R in data. Races

Select New Class1

//        {

Year= R.date.year

//        }). ToList ();

}

}

}

}


The CLASS1 code that is used to produce the collection used by the TreeView control

Using System;

Using System.Collections.Generic;

Using System.Linq;

Using System.Text;

Using System.Threading.Tasks;


Namespace WpfApplication73

{


public static Class F1datacontext

{

public static formula1v2entities Data {get; set;}

}

public class Class1

{

public int year {get; set;}

Public ienumerable<f1race>races

{

Get

{

Return (from R in F1DataContext.Data.Races

where r.date.year = = Year

R.date

Select New F1race

{

Date = R.date,

Country = R.circuits.country

}). ToList ();

}

}

}

public class F1race

{

public string Country {get; set;}

Public DateTime Date {get; set;}

Public ienumerable<f1raceresult> Results

{

Get

{

Return (from RR in F1DataContext.Data.RaceResults

The Where RR. Races.date = = this. Date

Select New F1raceresult

{

Position = RR. Position,

Racer = RR. Racers.firstname + "" + RR. Racers.lastname

}). ToList ();


}

}


}


public class F1raceresult

{

public int Position {get; set;}

public string Racer {get; set;}


}

}


Application of the "C #" ADO. Net entities framework in the WPF TreeView

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.