欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

WPF拖動DataGrid滾動條時內(nèi)容混亂的解決方法

 更新時間:2016年10月12日 10:31:44   作者:sunny906  
這篇文章主要介紹了WPF拖動DataGrid滾動條時內(nèi)容混亂的解決方法

在WPF中,如果DataGrid里使用了模板列,當拖動滾動條時,往往會出現(xiàn)列表內(nèi)容顯示混亂的情況。解決方法就是在Binding的時候給UpdateSourceTrigger賦值。

 <Grid>
  <Grid.RowDefinitions>
   <RowDefinition Height="25"></RowDefinition>
   <RowDefinition></RowDefinition>
  </Grid.RowDefinitions>
  <Button Height="23" Click="Button_Click" Content="Click" Grid.Row="0"></Button>
  <DataGrid Name="dgStudent" AutoGenerateColumns="False" IsEnabled="True" Grid.Row="1"
     EnableColumnVirtualization="True" EnableRowVirtualization="True">
   <DataGrid.Columns>
    <DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="80"></DataGridTextColumn>
    <DataGridTemplateColumn Header="Age" Width="70">
     <DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
       <TextBox Margin="5" Text="{Binding Age, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
      </DataTemplate>
     </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
    <DataGridTemplateColumn Header="Course" Width="100">
     <DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
       <ComboBox Margin="5" ItemsSource="{Binding CourseSource}" Text="{Binding Course, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></ComboBox>
      </DataTemplate>
     </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
   </DataGrid.Columns>
  </DataGrid>
 </Grid>

后臺代碼如下:

 public class Student
 {
  public string Name { get; set; }
  public string Age { get; set; }
  public List<string> CourseSource { get; set; } = new List<string>() { "C", "C++", "C#" };
  public string Course { get; set; }
 }

 private void Button_Click(object sender, RoutedEventArgs e)
  {
   var students = new List<Student>();
   for (int i = 1; i <= 50; i++)
   {
    var student = new Student()
    {
     Name = $"student{i}"
    };
    students.Add(student);
   }
   this.dgStudent.ItemsSource = null;
   this.dgStudent.ItemsSource = students;
  }

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • C#操作PowerPoint的方法

    C#操作PowerPoint的方法

    這篇文章主要介紹了C#操作PowerPoint的方法,涉及C#針對PowerPoint的打開、讀取、播放等技巧,非常具有實用價值,需要的朋友可以參考下
    2015-04-04
  • 遞歸案例分享

    遞歸案例分享

    一般定義:程序調(diào)用自身的編程技巧稱為遞歸( recursion)。
    2014-05-05
  • 詳解C#中Dictionary<TKey,TValue>的存儲結構

    詳解C#中Dictionary<TKey,TValue>的存儲結構

    無論是實際的項目中,還是在我們學習的過程中,都會重點的應用到Dictionary<TKey,?TValue>這個存儲類型,所以本文就來為大家介紹一下這一存儲結構的相關知識,希望對大家有所幫助
    2023-11-11
  • 使用Spire.Barcode程序庫生成二維碼的實例解析

    使用Spire.Barcode程序庫生成二維碼的實例解析

    這篇文章主要介紹了使用Spire.Barcode程序庫生成二維碼的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-12-12
  • C#中Response.Write常見問題匯總

    C#中Response.Write常見問題匯總

    這篇文章主要介紹了C#中Response.Write常見問題匯總,總結了C#中Response.Write的常用技巧,非常實用,需要的朋友可以參考下
    2014-09-09
  • 使用C#實現(xiàn)RTP數(shù)據(jù)包傳輸 參照RFC3550

    使用C#實現(xiàn)RTP數(shù)據(jù)包傳輸 參照RFC3550

    本篇文章小編為大家介紹,使用C#實現(xiàn)RTP數(shù)據(jù)包傳輸 參照RFC3550,需要的朋友參考下
    2013-04-04
  • C#?代碼大小寫規(guī)范說明

    C#?代碼大小寫規(guī)范說明

    這篇文章主要介紹了C#?代碼大小寫規(guī)范說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • C# 拷貝數(shù)組的幾種方法(總結)

    C# 拷貝數(shù)組的幾種方法(總結)

    下面小編就為大家?guī)硪黄狢# 拷貝數(shù)組的幾種方法(總結)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-08-08
  • C#?基于TCP?實現(xiàn)掃描指定ip端口的方式示例

    C#?基于TCP?實現(xiàn)掃描指定ip端口的方式示例

    本文主要介紹了C#基于TCP實現(xiàn)掃描指定ip端口的方式示例,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • c#?定期重啟程序操作的實現(xiàn)

    c#?定期重啟程序操作的實現(xiàn)

    本文主要介紹了c#?定期重啟程序操作的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-09-09

最新評論