<Window x:Class="WPfDataGrid.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="450" Width="525" Loaded="Window_Loaded">
<Grid>
<DataGrid x:Name="dgrdEmployee" Width="300" Height="300" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"/>
<Button Content="Navigation" x:Name="BtnNavigation" Width="90" Height="40" Margin="204,336,209,-15" />
</Grid>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public class Employees
{
public string Name { get; set; }
public string Id { get; set; }
public string Address { get; set; }
}
public List<Employees> EmployeeList()
{
XDocument employees = XDocument.Load(@"C:\Employees.xml");
List<Employees> employee = (from em in employees.Descendants("Employee")
select new Employees
{
Name = em.Element("Name").Value,
Id = em.Element("Id").Value,
Address = em.Element("Address").Value
}).ToList();
return employee;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
dgrdEmployee.ItemsSource = EmployeeList();
}
}
使用上面的代码,我得到以下结果。
如果数据网格滚动查看器可见,则按钮应可见,否则按钮应折叠。这样做有什么改变吗?
我尝试了类似下面的东西。但这对我来说没有意义。
<Button Content="Navigation" x:Name="BtnNavigation" Visibility="{Binding Visibility, ElementName=dgrdEmployee.ScrollViewer}" Width="90" Height="40" Margin="204,336,209,-15" />