【问题标题】:How to specify the width of the datagrid column to occupy the remaining space?如何指定datagrid列的宽度以占用剩余空间?
【发布时间】:2012-07-07 14:24:54
【问题描述】:

我正在开发 silverlight 4 应用程序。我有以下数据网格

<data:DataGrid x:Name="StudentDataGrid" AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" Margin="176,96,0,0" VerticalAlignment="Top" Width="200">
            <data:DataGrid.Columns>
                <data:DataGridTextColumn Header="First Name" Binding="{Binding FirstName}"></data:DataGridTextColumn>
                <data:DataGridTextColumn Width="*" Header="Last Name" Binding="{Binding LastName}" ></data:DataGridTextColumn>

            </data:DataGrid.Columns>
        </data:DataGrid>

我将以下列表绑定到此数据网格

 public List<Student> GetStudents()
        {
            List<Student> studentList = new List<Student>();
            Student s1 = new Student();
            s1.FirstName = "Anil";
            s1.LastName = "Jadhav";
            Student s2 = new Student();
            s2.FirstName = "Shyam";
            s2.LastName = "Jodh";
            studentList.Add(s1);
            studentList.Add(s2);
            return studentList;
        }

代码运行良好。 * 宽度占用剩余空间。但是当 s1.FirstName 被赋值时,它的字符串很长,然后代码运行但数据网格不显示滚动条。 LastName 列位于右侧并被隐藏。我不想增加datagrd的宽度。如何解决上述问题?为什么datagrid不显示滚动条?您能否提供我可以解决上述问题的任何代码或链接。

【问题讨论】:

    标签: c# silverlight-4.0 datagrid column-width


    【解决方案1】:

    此链接here 描述了针对此问题的解决方案。我有点怀疑,因为它不适用于 WPF(我没有 Silverlight),所以有兴趣了解它是否有效。

    否则我认为您必须动态设置最后一列的宽度,例如使用触发器。

    【讨论】:

      猜你喜欢
      • 2013-03-09
      • 2013-07-12
      • 2013-02-22
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 2018-10-09
      • 1970-01-01
      相关资源
      最近更新 更多