關注點:
一、 在Xml不一樣的兩個頂級元素Category中分別做爲兩個ListBox主綁定源,怎樣在2個主綁定源對應的1個從綁定源來講,當選擇任意項時,從綁定源的DataContext怎麼切換?app
private void HandleSelectionChanged(object sender, SelectionChangedEventArgs args) { if (sender == null) return; Details.DataContext = (sender as ListBox).DataContext; }
二、怎樣在對Xaml進行編碼時,同時執行xaml顯示結果?ide
protected void HandleTextChanged(object sender, TextChangedEventArgs me) { if (RealTimeUpdate) ParseCurrentBuffer(); } private void ParseCurrentBuffer() { try { var ms = new MemoryStream(); var sw = new StreamWriter(ms); var str = TextBox1.Text; sw.Write(str); sw.Flush(); ms.Flush(); ms.Position = 0; try { var content = XamlReader.Load(ms); if (content != null) { cc.Children.Clear(); cc.Children.Add((UIElement) content); } TextBox1.Foreground = Brushes.Black; ErrorText.Text = ""; } catch (XamlParseException xpe) { TextBox1.Foreground = Brushes.Red; TextBox1.TextWrapping = TextWrapping.Wrap; ErrorText.Text = xpe.Message; } } catch (Exception) { // ignored } }
三、預覽及代碼區的切換及各佔通常?佈局
protected void ShowPreview(object sender, RoutedEventArgs args) { PreviewRow.Height = new GridLength(1, GridUnitType.Star); CodeRow.Height = new GridLength(0); } protected void ShowCode(object sender, RoutedEventArgs args) { PreviewRow.Height = new GridLength(0); CodeRow.Height = new GridLength(1, GridUnitType.Star); } protected void ShowSplit(object sender, RoutedEventArgs args) { PreviewRow.Height = new GridLength(1, GridUnitType.Star); CodeRow.Height = new GridLength(1, GridUnitType.Star); }
四、Xpath規則:編碼
author
當前上下文中的全部 <author> 元素。spa
first.name
當前上下文中的全部 <first.name> 元素。code
/bookstore
此文檔的文檔元素 ( <bookstore>)。xml
//author
文檔中的全部 <author> 元素。對象
book[/bookstore/@specialty=@style]
style 屬性值等於文檔根處 <bookstore> 元素的 specialty 屬性值的全部 <book> 元素。ip
author/first-name
做爲 <author> 元素子級的全部 <first-name> 元素。內存
bookstore//title
<bookstore> 元素中一級或多級深度的全部 <title> 元素(任意後代)。 注意,此表達式不一樣於下一行中的表達式。
bookstore/*/title
做爲 <bookstore> 元素的孫代的全部 <title> 元素。
bookstore//book/excerpt//emph
位於 <book> 元素的 <excerpt> 子級內任意位置和位於 <bookstore> 元素內任意位置的全部 <emph> 元素。
.//title
當前上下文中一級或多級深度的全部 <title> 元素。 注意,本質上只有這種狀況須要句點表示法。
author/*
做爲 <author> 元素子級的全部元素。
book/*/last-name
做爲 <book> 元素孫級的 <last-name> 全部元素。
/
當前上下文的全部孫級元素。
*[@specialty]
具備 specialty 屬性的全部元素。
@style
當前上下文的 style 屬性。
price/@exchange
當前上下文中 <price> 元素上的 exchange 屬性。
price/@exchange/total
返回空節點集,由於屬性不包含元素子級。 XML 路徑語言 (XPath) 語法容許使用此表達式,可是嚴格意義上講無效。
book[@style]
當前上下文的具備 style 屬性的 <book> 全部元素。
book/@style
當前上下文的全部 <book> 元素的 style 屬性。
@*
當前元素上下文的全部屬性。
./first-name
當前上下文節點中的全部 <first-name> 元素。 注意,此表達式等效於下一行中的表達式。
first-name
當前上下文節點中的全部 <first-name> 元素。
author[1]
當前上下文節點中的第一個 <author> 元素。
authorfirst-name
具備 <first-name> 子級的第三個 <author> 元素。
my:book
my 命名空間中的 <book> 元素。
my:*
my 命名空間中的全部元素。
@my:* my 命名空間中的全部屬性(不包括 my 命名空間中的元素的未限定屬性)。