当RadGridView中嵌套RadComboBox,且RadGridView的高度不够出现滚动条时,上下拉动滚动条后,RadComboBox中的选中值将丢失!

  如下图:

  滚动条未拖动前

  

  滚动条上下拖动后(注意下图的高亮部分)

  

  重现该Bug的测试代码:

  Model层

  TextValueObject.cs

namespace RadControlsBug.Model
{
    public class TextValueObject
    {
        public string Text { set; get; }
  
        public string Value { set; get; }
    }
}

  SexType.cs

namespace RadControlsBug.Model
{
    public class SexType
    {
        /// <summary>
        /// 男
        /// </summary>
        public static string Male = "男";
  
        /// <summary>
        /// 女
        /// </summary>
        public static string FeMale = "女";
    }
}

  SexTypeCollection.cs

using System.Collections.Generic;
  
namespace RadControlsBug.Model
{
    public static class SexTypeCollection
    {
        private static List<TextValueObject> _items = new List<TextValueObject>();
  
        public static List<TextValueObject> Items
        {
            get { return _items; }
            set { _items = value; }
        }
  
        static SexTypeCollection() 
        {
            _items.Add(new TextValueObject() { Text = "男", Value = SexType.Male });
            _items.Add(new TextValueObject() { Text = "女", Value = SexType.FeMale });
        }
    }
}

  Person.cs

using System.Collections.Generic;
  
namespace RadControlsBug.Model
{
    public class Person
    {
        public string Name { set; get; }
  
        public string Sex { set; get; }
  
        private  List<TextValueObject> _sexItems = SexTypeCollection.Items;
  
        public List<TextValueObject> SexItems { get { return _sexItems; } }
  
    }
}

  Company.cs

using System.Collections.ObjectModel;
  
namespace RadControlsBug.Model
{
    public class Company
    {
        private ObservableCollection<Person> _employees = new ObservableCollection<Person>();
  
        public ObservableCollection<Person> Employees
        {
            get { return _employees; }
            set { _employees = value; }
        }
  
  
        public Company() 
        {
            this._employees.Add(new Person() { Name = "张三", Sex = SexType.Male });
            this._employees.Add(new Person() { Name = "李四", Sex = SexType.FeMale });
            this._employees.Add(new Person() { Name = "王五", Sex = SexType.Male });
            this._employees.Add(new Person() { Name = "赵六", Sex = SexType.FeMale });
            this._employees.Add(new Person() { Name = "孙七", Sex = SexType.Male });
            this._employees.Add(new Person() { Name = "杨九", Sex = SexType.FeMale });
            this._employees.Add(new Person() { Name = "胡十", Sex = SexType.Male });
        }
  
    }
}

  UI层:

  MainPage.Xaml:

<UserControl x:Class="RadControlsBug.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
  
    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
            <telerik:RadGridView ShowGroupPanel="False" RowIndicatorVisibility="Collapsed" CanUserFreezeColumns="False" AutoGenerateColumns="False" ItemsSource="{Binding Employees,Mode=TwoWay}" Width="300" Height="120" Name="gridView1">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewColumn   Header="姓名" Width="80" >
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadMaskedTextBox Value="{Binding Name,Mode=TwoWay}" MaskType="None"></telerik:RadMaskedTextBox>
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                    <telerik:GridViewColumn   Header="性别" Width="80" >
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadComboBox ItemsSource="{Binding SexItems,Mode=TwoWay}" SelectedValue="{Binding Sex,Mode=TwoWay}" SelectedValuePath="Value" DisplayMemberPath="Text"/>
                                  
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
             
        </StackPanel>
    </Grid>
</UserControl>

  MainPage.Xaml.cs:

using System.Windows;
using System.Windows.Controls;
using RadControlsBug.Model;
  
namespace RadControlsBug
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
  
            this.Loaded += new RoutedEventHandler(Page_Loaded);
        }
  
        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            Company _viewModel = new Company();
            this.DataContext = _viewModel;
              
        }
          
    }
}

  该问题曾经困扰我长达2周之久,在Telerik的论坛上提问也未得到回复。

  曾经反复尝试,发现解决方法居然极其简单:

  <telerik:RadComboBox ItemsSource="{Binding SexItems,Mode=TwoWay}" SelectedValue="{Binding Sex,Mode=TwoWay}" SelectedValuePath="Value" DisplayMemberPath="Text"/>

  改成:

  <telerik:RadComboBox  SelectedValue="{Binding Sex,Mode=TwoWay}" SelectedValuePath="Value" DisplayMemberPath="Text" ItemsSource="{Binding SexItems,Mode=TwoWay}"/>

  后,问题奇迹般的解决了!

  分享于此,希望有助于遇到同样问题的朋友。(个人分析:有可能telerik的开发人员在解析XAML时,判断逻辑依赖于属性出现的顺序导致--胡猜的,我也没去看它的源码)

  最后谈一下我个人对于Telerik RadControls For Silverlight这套控件的感受,用这套控件做项目开发已经有近3个月的时间,总体感觉还不错,能大幅提高团队的开发效率,官方有详细文档和示例, 上手非常容易,而且客观来讲,BUG也比较少(用了3个月,基本上才发现这一个比较诡异的BUG),此外,如果是正版用户,官方还提供源码,并有一年的免 费升级期限,每季度官方均会对整套控件做一次升级(主要是修复之前的BUG,以及增加一些新功能)。 从成本上考虑,一套控件的售价9k RMB左右(无Licence数量限制,而且能拿到源码任意修改),国内用户可在慧都控件网上直接购买,对于公司来讲这个成本其实并不高(相比公司招人自 己实现这些控件的功能而言,9k多其实可以忽略不计了),如果您的公司打算致力于企业级应用的RIA开发,建议使用。

Silverlight:telerik RadControls中RadGridView的一个Bug及解决办法(转载)的更多相关文章

  1. Excel在任务栏中只显示一个窗口的解决办法

     Excel在任务栏中只显示一个窗口的解决办法  以前朋友遇到过这个问题,这次自己又遇到了,习惯了以前的那种在任务栏中显示全部窗口,方便用Alt+Tab键进行切换. 如果同时打开许多Excel工作簿, ...

  2. asp.net开发中遇到的奇葩bug及解决办法(会持续更新。。。)

    1,不知道你们遇没遇到过,在vs2010或更高版本上运行程序的时候,完全没问题,放在IIS中出现了问题,就比如左侧是菜单项,点击菜单右边显示,如果菜单链接是这样:content.aspx,而另一个链接 ...

  3. 记CRenderTarget:DrawText()绘制中文乱码的BUG及解决办法

    原文:记CRenderTarget:DrawText()绘制中文乱码的BUG及解决办法 转载请注明出处:http://www.cnblogs.com/Ray1024 一.问题描述 在MFC中使用Dir ...

  4. 【转载】IE浏览器常见的9个css Bug以及解决办法

    IE浏览器常见的9个css Bug以及解决办法 我们在浏览网页的时候经常看见这样的现象:某个网页在IE6浏览器中打开很正常,但是在IE8里面打开可能完全变形了.或者也有可能出现完全相反的现象.这让We ...

  5. IIS关于“ 配置错误 不能在此路径中使用此配置节”的解决办法

    IIS关于“ 配置错误 不能在此路径中使用此配置节”的解决办法 原文链接:http://www.cnblogs.com/200325074/p/3679316.html 今天刚安装好IIS8.5, 我 ...

  6. 在ASP.net中的UpdatePanel,弹窗失败解决办法

    原文:在ASP.net中的UpdatePanel,弹窗失败解决办法 最开始我用: Response.Write("<script>alert('和哈呵呵呵呵呵呵!')</s ...

  7. 工作总结 EntityFramework中出现DateTime2异常的完美解决办法

    EntityFramework中出现DateTime2异常的完美解决办法   今天在使用entityframework往数据库插入数据的时候,突然出现了一个数据类型转换异常的问题: System.Da ...

  8. Dumpzilla工具第615行bug的解决办法

    Dumpzilla工具第615行bug的解决办法   在Dumpzilla使用选项frequency时,会提示SQL语法错误.这是由于其中SQL语句编写错误.需要将615行中: where url l ...

  9. Ubuntu中Android SDK Manager无法更新解决办法

    Ubuntu中Android SDK Manager无法更新解决办法http://hi.baidu.com/petercao2008/item/d7a64441f04668e81e19bc1a

随机推荐

  1. Codeforces #432 Div2 D

    #432 Div2 D 题意 给出一些数字,如果这些数字的的 \(gcd\) 不为1则称这些数字 \(good\). 可以有两种操作: 花费 x 删掉一个数 花费 y 将一个数加 1 问使这些数 \( ...

  2. centos 7 下发送邮件设置

    使用sendmail发邮件的配置 yum -y install sendmailservice sendmail start vim body.txttest mail from linux. mai ...

  3. Xamarin XAML语言教程基本页面ContentPage占用面积(二)

    Xamarin XAML语言教程基本页面ContentPage占用面积(二) Xamarin XAML语言教程基本页面ContentPage占用面积(二)内容页面的添加 为了方便用户添加Content ...

  4. Spring Struts里用到的设计模式

    Bean工厂的Factory模式 AOP的Proxy模式

  5. Combination Sum IV -- LeetCode

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  6. [Atcoder Grand Contest 002] Tutorial

    Link: AGC002 传送门 A: …… #include <bits/stdc++.h> using namespace std; int a,b; int main() { sca ...

  7. 【块状树】【树链剖分】【线段树】bzoj3531 [Sdoi2014]旅行

    离线后以宗教为第一关键字,操作时间为第二关键字排序. <法一>块状树,线下ac,线上tle…… #include<cstdio> #include<cmath> # ...

  8. python3开发进阶-Django框架的ORM常用字段和参数

    阅读目录 常用字段 字段合集 自定义字段 字段参数 关系参数 多对多的关联关系的三种方式 一.常用字段 AutoField int自增列,必须填入参数 primary_key=True.当model中 ...

  9. easyui中一键清空搜索栏搜索条件的思路

    $.fn.clearAllSearchPanel = function () { var $id = $(this); $id.find(".form-control").each ...

  10. [转] C/C++中printf和C++中cout的输出格式

    原文地址 一. Printf 输出格式 C中格式字符串的一般形式为: %[标志][输出最小宽度][.精度][长度]类型,其中方括号[]中的项为可选项.各项的意义介绍如下:1.类型类型字符用以表示输出数 ...