Guest User

Untitled

a guest
Aug 2nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. <XmlDataProvider x:Key="Employees" XPath="/Employees/*">
  2. <x:XData>
  3. <Employees xmlns="">
  4. <Employee Name="Terry Adams" Type="FTE" EmployeeNumber="1" />
  5. <Employee Name="Claire O&apos;Donnell" Type="FTE" EmployeeNumber="12345" />
  6. <Employee Name="Palle Peterson" Type="FTE" EmployeeNumber="5678" />
  7. <Employee Name="Amy E. Alberts" Type="CSG" EmployeeNumber="99222" />
  8. <Employee Name="Stefan Hesse" Type="Vendor" EmployeeNumber="-" />
  9. </Employees>
  10. </x:XData>
  11. </XmlDataProvider>
  12.  
  13. <DataTemplate x:Key="EmployeeItemTemplate">
  14. <TextBlock Text="{Binding XPath=@Name}" />
  15. </DataTemplate>
  16.  
  17.  
  18. ...
  19.  
  20. <ListBox Name="employeeListBox"
  21. ItemsSource="{Binding Source={StaticResource Employees}}"
  22. ItemTemplate="{StaticResource EmployeeItemTemplate}"
  23. SelectedValue="12345"
  24. SelectedValuePath="@EmployeeNumber"/>
  25.  
  26. <TextBlock Text="{Binding ElementName=employeeListBox,
  27. Path=SelectedValue}"/>
  28.  
  29. <Window x:Class="WpfStaticDataBinding.XMLWindows"
  30. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  31. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  32. xmlns:sys="clr-namespace:System;assembly=mscorlib"
  33. Title="XMLWindows" Height="152" Width="294">
  34. <Window.Resources>
  35. <XmlDataProvider x:Key="MockList" XPath="/MockObjects/*" >
  36. <x:XData >
  37. <MockObjects xmlns="">
  38. <MockObject Name="Louis" Type="TTTT" Number="1" />
  39. <MockObject Name="Joseph" Type="TTTT" Number="2" />
  40. <MockObject Name="Papineau" Type="ZZZZ" Number="3" />
  41. </MockObjects>
  42. </x:XData>
  43. </XmlDataProvider>
  44. </Window.Resources>
  45. <Grid DataContext="{Binding Source={StaticResource MockList}}">
  46. <DataGrid HorizontalAlignment="Stretch" Margin="10" VerticalAlignment="Stretch"
  47. ItemsSource="{Binding Mode=Default, XPath=/MockObjects/MockObject}"
  48. AutoGenerateColumns="False">
  49. <DataGrid.Columns>
  50. <DataGridTextColumn Header="Name" Binding="{Binding XPath=@Name}" ></DataGridTextColumn>
  51. <DataGridTextColumn Header="Type" Binding="{Binding XPath=@Type}"></DataGridTextColumn>
  52. <DataGridTextColumn Header="Number" Binding="{Binding XPath=@Number}"></DataGridTextColumn>
  53. </DataGrid.Columns>
  54. </DataGrid>
  55. </Grid>
  56.  
  57. <Grid DataContext="{Binding Source={StaticResource MockList}}">
  58. <DataGrid HorizontalAlignment="Stretch" Margin="10" VerticalAlignment="Stretch"
  59. ItemsSource="{Binding Mode=Default, XPath=/MockObjects/MockObject}">
  60. </DataGrid>
  61. </Grid>
  62.  
  63. namespace WpfStaticDataBinding
  64. {
  65. public class MockRecord
  66. {
  67. public string FirstName { get; set; }
  68. public string LastName { get; set; }
  69. public string Email { get; set; }
  70. }
  71. }
  72.  
  73. <Window x:Class="WpfStaticDataBinding.MainWindow"
  74. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  75. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  76. xmlns:local="clr-namespace:WpfStaticDataBinding"
  77. Title="MainWindow" Height="157" Width="302">
  78. <Window.Resources>
  79. <ResourceDictionary>
  80. <x:Array x:Key="MyDumbMockedList" Type="local:MockRecord">
  81. <local:MockRecord FirstName="Fred" LastName="Flintstone" Email="fred@noemail.org" />
  82. <local:MockRecord FirstName="Wilma" LastName="Flintstone" Email="wilma@noemail.org" />
  83. <local:MockRecord FirstName="Barney" LastName="Rubble" Email="barney@noemail.org" />
  84. </x:Array>
  85. </ResourceDictionary>
  86. </Window.Resources>
  87. <Grid>
  88. <DataGrid Margin="10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
  89. ItemsSource="{Binding Source={StaticResource MyDumbMockedList}}"/>
  90. </Grid>
  91.  
  92. namespace TestNamespace
  93. {
  94. public class MockRecord
  95. {
  96. public string FirstName { get; set; }
  97. public string LastName { get; set; }
  98. public string Email { get; set; }
  99. }
  100. }
  101.  
  102. <DataGrid xmlns:local="clr-namespace:TestNamespace">
  103.  
  104. <DataGrid.Columns>
  105. <DataGridTextColumn Header="First Name" Binding="{Binding FirstName}" />
  106. <DataGridTextColumn Header="Rate" Binding="{Binding LastName}" />
  107. <DataGridTextColumn Header="Cost" Binding="{Binding Email}" />
  108. </DataGrid.Columns>
  109.  
  110. <!-- Static Data which will automatically go in the datagrid -->
  111. <local:MockRecord FirstName="Fred" LastName="Flintstone" Email="fred@noemail.org" />
  112. <local:MockRecord FirstName="Wilma" LastName="Flintstone" Email="wilma@noemail.org" />
  113. <local:MockRecord FirstName="Barney" LastName="Rubble" Email="barney@noemail.org" />
  114. </DataGrid>
Add Comment
Please, Sign In to add comment