关注点:
一、 在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 命名空间中的元素的未限定属性)。