バインディングとテンプレートを使用してWPFで階層データ構造を表示する

はじめに


WPFでの階層構造(ネストの任意のレベル)の形式でのデータセットの表現は非常に簡単です。 原則として、これにはSystem.Windows.Controls.TreeViewクラスが使用され、結果は次のようになります。





このようなツリーを構築する2つのケースを示します。これらは、 データソースによって異なります。





アプリケーションは、あるデータソースを別のデータソースに動的に置き換える機能を実装します。

まず、情報を取得するデータソースを作成する必要があります。 これらのソースは次のとおりです。

  1. MyTestDb.mdfデータベース
  2. XML xmlfile1.xml


2つのプロジェクト(プロジェクト)で構成される単一のソリューションが作成されます。

  1. Linq2SqlProjectは、リレーショナルデータベース構造のオブジェクト投影であるクラスのセットを含むライブラリです。
  2. WpfGuiProject -WPFテクノロジーを使用して作成されたアプリケーションのグラフィカル部分(GUI)。 同じプロジェクトで、XMLデータの操作に関するコードが投稿されます。


このトピックで説明されているすべてのデータソースとの相互作用は、LINQテクノロジを使用して実装されます。



1.データベースの作成



この例では、データベースは2つのテーブルで構成されます-これは、前述の問題の解決策を示すのに十分です。







MySchema.Categoriesテーブルに次のエントリを追加しました。







次のデータがMySchema.Booksテーブルに入力されます。







例を複雑にしないために、クライアントアプリケーションがデータベースと連携するデータベースに一連のストアドプロシージャを作成しません(実際の作業ではもちろん、実行の可能性を避けるために、ストアドプロシージャを通じてデータベースと対話するだけですSQLインジェクション)。

ここから上記のデータベースダウンロードし、DBMSに接続します。



2.オブジェクト指向のデータベースプロジェクションを作成する





1.新しい空のソリューション(ソリューション)を作成し、「TreeStructureBrowse」という名前を割り当てます。







2.ソリューションエクスプローラーでソリューションの名前をクリックして取得したコンテキストメニューから、[追加] => [新しいプロジェクト...]を選択します。

3.プロジェクトタイプ「クラスライブラリ」を選択し、プロジェクトに「Linq2Sql」という名前を割り当てて、OKキーを押します。

4.手順3で追加したプロジェクトの名前をクリックして取得したコンテキストメニューから、[追加] => [新しいアイテム]を選択します...

5.要素「LINQ to SQL Classes」を選択し、ファイル名「MyTestDb」を割り当てます。







6. [表示]メニューから[サーバーエクスプローラー]を選択します。 表示されるウィンドウで、[データベースに接続]ボタンをクリックします。







7.接続文字列に必要なすべてのパラメーターを指定します(私の場合、Windows認証が使用されます)。







8. [接続テスト]ボタンをクリックして接続できることを確認し、[OK]ボタンをクリックして[接続の追加]ウィンドウを閉じます。

9. [サーバーエクスプローラー]ウィンドウに次の図が表示されます。







ps powercompは私のコンピューター名です



10. Shiftキーを押しながら、両方のテーブル(ブックとカテゴリ)を選択し、マウスでそれらをMyTestDb.dbml *タブにドラッグすると、次の図が表示されます。







11.プロジェクトを保存し、Build => Rebuild Solutionコマンドを実行します。



T.O. リレーショナルベースのオブジェクト指向モデルを作成しました。これは、問題を解決する際の最初のキーポイント(3つのうち)です。



3.グラフィカルパーツ(GUI)の作成、コンバーターの作成、テンプレートの作成



1.前のセクションで作成したソリューションでは、WpfGuiProjectという名前で設定して新しいプロジェクトを追加します。







2.ソリューションに追加したプロジェクトの名前を右クリックして表示されるコンテキストメニューから、「スタートアッププロジェクトとして設定」項目を選択し、GUIプロジェクトをデフォルトで実行します。

3. Linq2SqlプロジェクトへのリンクをWpfGuiProjectプロジェクトに追加します。







4.プロジェクトにリソースディクショナリを追加します。プロジェクトの名前を右クリックして呼び出されるコンテキストメニューから、[追加] => [リソースディクショナリ...]を選択し、表示されるダイアログボックスで同じ名前の要素を選択します。







5.プロジェクトのコンテキストメニューから、「クラス」タイプの新しいファイルをプロジェクトに追加し、「MyConverters.cs」という名前を割り当てます。

6.アセンブリ「System.Data.Linq」をプロジェクトに接続します。

7. 5項で作成したファイルに、次のコードを記述します。



using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  1. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  2. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  3. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  4. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  5. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  6. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  7. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  8. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  9. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  10. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  11. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  12. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  13. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  14. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  15. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  16. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  17. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  18. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  19. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  20. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  21. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  22. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  23. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  24. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  25. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  26. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  27. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  28. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  29. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  30. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  31. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  32. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  33. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  34. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  35. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  36. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  37. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  38. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  39. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  40. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  41. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  42. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  43. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  44. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  45. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  46. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  47. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  48. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  49. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  50. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



  51. using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .



using System; using System.Collections. Generic ; using System.Linq; using System.Text; using System.Windows.Data; using Linq2Sql; using System.Xml.Linq; namespace WpfGuiProject { // Category. - Category. public sealed class CategoryValueConverter : IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is Category) { Category x = (Category) value ; return (x).Categories.Where(n => n.ParrentCategoryId == x.CategoryId).OrderBy(n => n.CategoryName); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } // XElement. - XElement, // Category. public sealed class XmlConverter :IValueConverter { public object Convert ( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ( value is XElement ) { XElement x = ( XElement ) value ; return x.Elements( "Category" ); } else { return null ; } } public object ConvertBack( object value , Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } } * This source code was highlighted with Source Code Highlighter .





節7で作成されたものは、私たちの前にある課題を解決するための2番目(3つのうち)の重要なポイントです-データバインディングを使用して実装された情報の階層視覚表現 コードでは、必要な子を取得するためのロジックを決定します。これは、階層モデルの構築に参加する必要があります。

8.「Dictionary1.xaml」ファイルを編集します。







  1. < ResourceDictionary xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:linq2Xml = "clr-namespace:System.Xml.Linq; assembly = System.Xml.Linq"
  4. xmlns:linq = "clr-namespace:Linq2Sql; assembly = Linq2Sql"
  5. xmlns:local = "clr-namespace:WpfGuiProject" >
  6. <!-データベースに接続する場合のTreeTableクラスのインスタンスの階層表示用テンプレート->
  7. < HierarchicalDataTemplate x:Key = "key1" DataType = "{x:Type linq:Category}" >
  8. <!-データソースを示し、それに基づいてパーティションツリーを形成する必要があります->
  9. < HierarchicalDataTemplate.ItemsSource >
  10. < バインディング パス = "。" >
  11. <!-これに関連して、カテゴリタイプの子要素のリストを取得できるコンバータを示します->
  12. < Binding.Converter >
  13. < ローカル:CategoryValueConverter />
  14. </ Binding.Converter >
  15. </ バインディング >
  16. </ HierarchicalDataTemplate.ItemsSource >
  17. <!-セクションツリーに表示される要素を視覚的に表現します->
  18. < DockPanel >
  19. < TextBlock Text = "{Binding Path = CategoryName}" >
  20. < TextBlock.ToolTip >
  21. < バインディング パス = "説明" />
  22. </ TextBlock.ToolTip >
  23. </ TextBlock >
  24. <!-セクションに直接配置された本の数->
  25. < TextBlock Name = "txtLeft" Text = "( " Grid。Column = "1" />
  26. < TextBlock Name = "txtCount" Text = "{Binding Path = Books.Count}" Grid = "2" />
  27. < TextBlock Name = "txtRight" Text = ")" Grid = "3" />
  28. </ DockPanel >
  29. </ HierarchicalDataTemplate >
  30. <!-データベースに接続する場合にBookクラスのインスタンスを表示するためのテンプレート->
  31. < DataTemplate DataType = "{x:タイプlinq:Book}" >
  32. < TextBlock Text = "{Binding Path = BookName}" >
  33. < TextBlock.ToolTip >
  34. < バインディング パス = "ToolTipText" />
  35. </ TextBlock.ToolTip >
  36. </ TextBlock >
  37. </ DataTemplate >
  38. <!-XMLファイルに接続する場合の階層データ表示用のテンプレート->
  39. < HierarchicalDataTemplate x:Key = "key2" DataType = "{x:タイプlinq2Xml:XElement}" >
  40. <!-データソースを示し、それに基づいてパーティションツリーを形成する必要があります->
  41. < HierarchicalDataTemplate.ItemsSource >
  42. < バインディング パス = "。" >
  43. <!-これに関連して、カテゴリタイプの子要素のリストを取得できるコンバータを示します->
  44. < Binding.Converter >
  45. < ローカル:XmlConverter />
  46. </ Binding.Converter >
  47. </ バインディング >
  48. </ HierarchicalDataTemplate.ItemsSource >
  49. <!-セクションツリーに表示される要素を視覚的に表現します->
  50. < TextBlock Text = "{Binding Path = Attribute [CategoryName] .Value}" >
  51. < TextBlock.ToolTip >
  52. < バインディング パス = "属性[ToolTipText] .Value" />
  53. </ TextBlock.ToolTip >
  54. </ TextBlock >
  55. </ HierarchicalDataTemplate >
  56. <!-XMLファイルへの接続の場合にBookクラスのインスタンスを表示するためのテンプレート->
  57. < DataTemplate x:Key = "key3" DataType = "{x:タイプlinq2Xml:XElement}" >
  58. < グリッド >
  59. < Grid.RowDefinitions >
  60. < RowDefinition />
  61. < RowDefinition Height = "Auto" />
  62. </ Grid.RowDefinitions >
  63. < TextBlock Text = "{Binding Path = Attribute [BookName] .Value}" >
  64. < TextBlock.ToolTip >
  65. < バインディング パス = "属性[ToolTipText] .Value" />
  66. </ TextBlock.ToolTip >
  67. </ TextBlock >
  68. </ グリッド >
  69. </ DataTemplate >
  70. </ ResourceDictionary >
*このソースコードは、 ソースコードハイライターで強調表示されました。




節8で作成されたxmlマークアップは3番目の重要なポイントです。 このマークアップでは、HierarchicalDataTemplateクラスを使用して、現在のテンプレートとの関係で子を取得するために使用するデータ表示テンプレートとコンバーターを定義しました。



次に、ウィンドウのグラフィカルな表現を形成し始めます。



9.「MainWindow.xaml」ファイルの内容を編集します。







  1. < ウィンドウ x:クラス = "WpfGuiProject.MainWindow"
  2. xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:linq = "clr-namespace:Linq2Sql; assembly = Linq2Sql"
  5. xmlns:local = "clr-namespace:WpfGuiProject"
  6. Title = "バインディングを使用したデータの階層表示" Height = "350" Width = "525" >
  7. <!-リソースファイルを含める->
  8. < Window.Resources >
  9. < ResourceDictionary >
  10. < ResourceDictionary.MergedDictionaries >
  11. < ResourceDictionary Source = "Dictionary1.xaml" />
  12. </ ResourceDictionary.MergedDictionaries >
  13. </ ResourceDictionary >
  14. </ Window.Resources >
  15. <!-ウィンドウの視覚的なコンテンツを形成する->
  16. < グリッド >
  17. < Grid.ColumnDefinitions >
  18. < ColumnDefinition Width = "50 *" />
  19. < ColumnDefinition Width = "Auto" />
  20. < ColumnDefinition Width = "50 *" />
  21. </ Grid.ColumnDefinitions >
  22. < Grid.RowDefinitions >
  23. < RowDefinition Height = "Auto" />
  24. < RowDefinition Height = "100 *" />
  25. < RowDefinition Height = "Auto" />
  26. </ Grid.RowDefinitions >
  27. <!-ツリー構造を表示します->
  28. < TreeView Name = "treeStructure" Margin = "2" Grid = "1" />
  29. <!-階層内の選択した要素のメモを表示します->
  30. < GroupBox Header = "Note" Margin = "2" Grid = "2" >
  31. < TextBlock Name = "selectedNodeDescription" TextWrapping = "Wrap" Text = "{Binding ElementName = treeStructure、Path = SelectedItem.Description}" />
  32. </ GroupBox >
  33. < GridSplitter Width = "5" Horizo​​ntalAlignment = "Center" VerticalAlignment = "Stretch" Grid = "1" グリッドRowSpan = "3" />
  34. < ListBox Name = "listBooks" Margin = "2" Grid = "2" グリッドRowSpan = "2" ItemsSource = "{Binding ElementName = treeStructure、Path = SelectedItem.Books}" />
  35. < GroupBox Header = "Note" Margin = "2" Grid = "2" グリッド = "2" >
  36. < TextBlock Name = "selectedBookDescription" TextWrapping = "Wrap" Text = "{Binding ElementName = listBooks、Path = SelectedItem.Description}" />
  37. </ GroupBox >
  38. <!-対象のデータソースの選択をユーザーに提供します。 このブロックは、定義されているXAMLマークアップの後に配置する必要があります
  39. treeStructure要素。 この要件は、RadioButton要素のXAMLマークアップに登録が含まれているという事実によるものです。
  40. 本体には、treeStructure要素を使用するコードがあり、XAMLドキュメントの規則に従って、
  41. 決定される前->
  42. < GroupBox Header = "Data Source" Margin = "2" >
  43. < StackPanel Margin = "2" >
  44. < RadioButton = "rbDatabase" コンテンツ = "MS SQL Server データベース " IsChecked = "True" Checked = "Change_DataSource" />
  45. < RadioButton Name = "rbXmlFile" Content = "XML file" IsChecked = "False" Checked = "Change_DataSource" />
  46. </ stackpanel >
  47. </ GroupBox >
  48. </ グリッド >
  49. </ ウィンドウ >
*このソースコードは、 ソースコードハイライターで強調表示されました。




このマークアップはそのようなウィンドウを形成します:







10.ファイル「XMLFile1.xml」をプロジェクトに追加します。これは代替データソースになります。







作成したファイルに、xml形式で記述されたデータを入力します。







  1. <? xml バージョン = "1.0" encoding = "utf-8">
  2. < MyXmlDocument >
  3. < カテゴリ CategoryName = "コンピュータ文学" 説明 = "さまざまな コンピュータ文学 " ToolTipText = "マイセクション" >
  4. < カテゴリ CategoryName = "Windowsアプリケーション" Description = "このOSは最も人気があります" ToolTipText = "My axis" >
  5. < カテゴリ CategoryName = "MS Office 2007" Description = "Office Suite" ToolTipText = "My Office" />
  6. < カテゴリ CategoryName = "Autodesk Products" Description = "Various CAD" ToolTipText = "My Choice" >
  7. < カテゴリ CategoryName = "AutoCAD" Description = "最も一般的なCAD" ToolTipText = "My CAD" >
  8. < Book BookName = "AutoCAD 2010. Poleschuk N.N." 説明 =「このCADに関する私の本」 ToolTipText =「参照」 />
  9. < Book BookName = "AutoCAD 2007、ユーザーの聖書。(著者は覚えていません)" Description = "このCADシステムの別の " ToolTipText = "古い本" />
  10. </ カテゴリー >
  11. < カテゴリ CategoryName = "Revit" Description = "新世代のCAD(BIM)" ToolTipText = "まだCADになっていない" />
  12. </ カテゴリー >
  13. </ カテゴリー >
  14. < カテゴリ CategoryName = "Linuxアプリケーション" Description = " フリーウェア OS" ToolTipText = "興味深いが、あまり一般的ではない" />
  15. </ カテゴリー >
  16. < カテゴリ CategoryName = "Classics" Description = "Classical Literature" ToolTipText = "一般的な開発に有用" >
  17. < Category CategoryName = "Tales and Stories" Description = "ロシアの著者による詩" ToolTipText = "For the soul" >
  18. < Book BookName = "Captain's daughter。A.S. Pushkin" Description = "School course" ToolTipText = "一度読んだ..." />
  19. </ カテゴリー >
  20. < カテゴリ CategoryName = "Poetry" Description = "国内作家の物語と物語" ToolTipText = "これも魂のためです" />
  21. </ カテゴリー >
  22. </ MyXmlDocument >
*このソースコードは、 ソースコードハイライターで強調表示されました。




11.ファイル「MainWindow.xaml.cs」に変更を加えます。







  1. システムを使用して ;
  2. System.Collections を使用します。 ジェネリック
  3. System.Linq を使用します。
  4. using System.Text;
  5. System.Windows を使用します。
  6. System.Windows.Controls を使用します。
  7. using System.Windows.Data;
  8. System.Windows.Documents を使用します。
  9. System.Windows.Input を使用します。
  10. System.Windows.Media を使用します。
  11. System.Windows.Media.Imaging を使用します。
  12. System.Windows.Navigation を使用します。
  13. System.Windows.Shapes を使用します。
  14. //必要な名前空間へのリンクを追加します
  15. Linq2Sql を使用
  16. System.Xml.Linq を使用します。
  17. 名前空間 WpfGuiProject
  18. {
  19. /// <summary>
  20. /// MainWindow.xamlの相互作用ロジック
  21. /// </ summary>
  22. パブリック 部分 クラス MainWindow:Window
  23. {
  24. XElement xml;
  25. パブリック MainWindow()
  26. {
  27. InitializeComponent();
  28. xml = XElement .Load( @ ".. \ .. \ XMLFile1.xml" );
  29. }
  30. //このメソッドには、ウィンドウに表示されるデータソースを示すためのすべてのロジックが含まれます
  31. private void Change_DataSource( オブジェクト送信者、RoutedEventArgs e)
  32. {
  33. if (rbDatabase.IsChecked == true//データベースがデータソースとして選択されます
  34. {
  35. listBooks.ItemTemplate = null ;
  36. treeStructure.ItemsSource = new MyTestDbDataContext()。Categories.Where(n => n.ParrentCategoryId == null );
  37. treeStructure.ItemTemplate =(HierarchicalDataTemplate)FindResource( " key1 " );
  38. //メモのバインドを設定します
  39. DescriptionBinding(selectedNodeDescription、 「SelectedItem.Description」 、treeStructure);
  40. DescriptionBinding(selectedBookDescription、 "SelectedItem.Description" 、listBooks);
  41. //ブックの表示バインディングを設定します
  42. バインドbind = new Binding( "SelectedItem.Books" ){Source = treeStructure};
  43. listBooks.SetBinding(ItemsControl.ItemsSourceProperty、バインド);
  44. }
  45. else //データソースとしてxmlファイルが選択されます
  46. {
  47. treeStructure.ItemsSource = xml.Elements( "Category" );
  48. treeStructure.ItemTemplate =(HierarchicalDataTemplate)FindResource( "key2" );
  49. //メモのバインドを設定します
  50. DescriptionBinding(selectedNodeDescription、 「SelectedItem.Attribute [Description] .Value」 、treeStructure);
  51. DescriptionBinding(selectedBookDescription、 「SelectedItem.Attribute [Description] .Value」 、listBooks);
  52. //ブックの表示バインディングを設定します
  53. listBooks.ItemTemplate =(DataTemplate)FindResource( "key3" );
  54. バインドbind = new Binding( "SelectedItem.Elements [Book]" ){Source = treeStructure};
  55. listBooks.SetBinding(ItemsControl.ItemsSourceProperty、バインド);
  56. }
  57. }
  58. /// <summary>
  59. ///データ表示バインディングを構成する
  60. /// </ summary>
  61. /// <param name = "textBlock">ノートテキストを表示するテキストオブジェクト</ param>
  62. /// <param name = "pathValue">パスバインディングの値</ param>
  63. /// <param name = "source"> Pathプロパティを通じてデータが読み取られるソースオブジェクトへの参照</ param>
  64. void DescriptionBinding(TextBlock textBlock、 string pathValue、コントロールソース)
  65. {
  66. textBlock.SetBinding(TextBlock.TextProperty、 新しいバインディング(pathValue){ソース=ソース});
  67. }
  68. }
  69. }
*このソースコードは、 ソースコードハイライターで強調表示されました。




これで、アプリケーションを実行して実行し、作業の結果を楽しむことができます... F5キーを押して、何があるかを確認します...



A.ソースはデータベースです。







B.ソースはxmlファイルです。







MS Visual Studio 2010形式のソリューション(ソリューション)のソースコードは、 ここからダウンロードできます



All Articles