2013-03-12 130 views
1
<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(); 
    } 
} 

以上代码,我得到以下结果。如何将wpf datagrid scrollviewer visiblity绑定到按钮可见性?

enter image description here

如果数据网格滚动查看器中显示的按钮应该是可见的,否则按钮应该是崩溃。有没有改变这样做?

我试过下面的东西。但对我来说这没有意义。

<Button Content="Navigation" x:Name="BtnNavigation" Visibility="{Binding Visibility, ElementName=dgrdEmployee.ScrollViewer}" Width="90" Height="40" Margin="204,336,209,-15" /> 

回答

0

ScrollViewer始终可见。 ScrollViewer将显示或隐藏其滚动条,具体取决于显示的数据量。

假设你可以获取到ScrollViewerVerticalScrollBarVisiblityHorizontalScrollBarVisiblity性能,你也许可以创建这些属性和按钮的Visibliity属性之间的MultiBinding。您可能还必须创建一个value converter,因为滚动条可见性属性使用不同的类型(除标准可见性值以外,还包括Auto值)。

+0

我不知道请帮我用代码。 – 2013-03-12 12:09:47