国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

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

2020-01-24 00:58:32
字體:
供稿:網(wǎng)友

在WPF中,如果DataGrid里使用了模板列,當(dāng)拖動(dòng)滾動(dòng)條時(shí),往往會(huì)出現(xiàn)列表內(nèi)容顯示混亂的情況。解決方法就是在Binding的時(shí)候給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>

后臺(tái)代碼如下:

 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;  }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 武穴市| 绍兴市| 平塘县| 巩留县| 屏山县| 太原市| 额尔古纳市| 江源县| 和田市| 积石山| 柞水县| 海兴县| 隆化县| 绥德县| 商水县| 长阳| 韶山市| 永康市| 灌阳县| 萝北县| 甘德县| 吉林市| 马鞍山市| 楚雄市| 新疆| 雷州市| 阿图什市| 治县。| 岑巩县| 普洱| 万载县| 上栗县| 邹平县| 宣威市| 南部县| 松滋市| 大庆市| 渝中区| 贺兰县| 深州市| 滁州市|