To facilitate the operation of the framework's tree structure, the WPF Basic Class library prepares visualtreehelper and Logicaltreehelper two helper classes, while also encapsulating some of the important base classes that are specifically used to manipulate the tree.
XAML is a declarative language, and the XAML editor creates a corresponding object for each label. There are two ways to assign a value to an object property in XAML:
1>, using strings for simple assignment;
2>, use property element for complex assignment.
A portion of a label's attibute corresponds to the object's property.
Note: When you assign a value by using the Attribute=value syntax, value can only be a string because of the XAML syntax constraint, which leads to two problems:
1>, if a class can be declared using the XAML language and allows its property to be mapped to the attribute of the XAML tag, it is necessary to prepare the appropriate transfer system for these properties
2>, because value is a string, its format complexity is limited, it is difficult to meet the requirements.
The solution to the first problem is to use the derived class of the TypeConverter class to override some TypeConverter methods in the derived class, a simple case like this:
Xaml:
<window x:class= "Text.mainwindow"
Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys= "Clr-namespace:system;assembly=mscorlib"
Xmlns:local= "Clr-namespace:text"
Xmlns:c= "Clr-namespace:system.collections;assembly=mscorlib"
Title= "WPF" windowstartuplocation= "Centerscreen" height= "width=" >
<Window.Resources>
<local:human x:key= "Human"child= "ABC"/>
</Window.Resources>
<StackPanel>
<button width= "height=" "margin=" 5 "click=" Button_Click "/>
</StackPanel>
</Window>
C # backend Code:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.IO;
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;
Using System.Xml;
Using System.Xml.Linq;
Using System.ComponentModel;
Namespace Text
{
[TypeConverter (typeof (Stringtohumantypeconverter))]
public class Human
{
public string Name {get; set;}
Public Human Child {get; set;}
}
public class Stringtohumantypeconverter:TypeConverter
{
public override ObjectConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
if (value is string)
{
Human h = new Human ();
H.name = value As String;
return h;
}
Return base. ConvertFrom (context, culture, value);
}
}
///<summary>
// MainWindow.xaml Interactive Logic
//</summary>
public partial class Mainwindow:window
{
private double o = 1.0;
public MainWindow ()
{
InitializeComponent ();
}
private void Button_Click (object sender, RoutedEventArgs e)
{
Human h = (Human) this. FindResource ("Human");
MessageBox.Show (H.child.name);
}
}
}
For specific use of Typyconverter see MSDN
This article is from the "Ink Pool small" blog, please be sure to keep this source http://306702895.blog.51cto.com/8366753/1614399
wpf-notes in layman's (2015.02.13)