- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我需要一种方法让 View 模型指示 View 上的 XamDataGrid
以最少的麻烦重新读取和重新绘制其单元格。我不想弄乱源代码并做一些不可持续的解决方法来引发它的事件(源代码可能会改变)。
为了让它更容易理解,我有一个全局静态类,它包含一些视觉提示配置,这些配置不会影响数据,但只会影响它们在网格中的表示方式(缩放、格式化等)。视觉操作发生在附加到工作正常的字段的 IValueConverter
实现中。有一个静态事件,当提示发生变化并且 View 模型订阅它并且事件正确触发时会触发。现在我只需要让事件处理程序使网格重新绘制。
有什么建议吗?
编辑:一些代码,如果有帮助的话:
转换器:
public class ScaleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType == typeof(double) || targetType == typeof(double?))
{
if (value == null && targetType == typeof(double?)) return null; // short circuit for null->null, nothing to scale
if (value is double) return (double)value / DisplayScale.Scale; // shortcut for direct scaling, no need to waste time on conversion
try
{
return System.Convert.ToDouble(value) / DisplayScale.Scale; // for convertible values, eat conversion exception
}
catch (Exception) {};
// if all esle fails return NaN
return double.NaN;
}
// fallthrough, return null, this should not happen, if it does it means converter is incomplete
return null;
}
...
}
全局显示比例
public class DisplayScale: NotificationObject
{
private static KeyValuePair<string, double> _ActiveScaling;
private static readonly object _lockHandle = new object(); // note: should not contest, but just to be on the safe side
public static event Action ScalingChanged;
public static List<KeyValuePair<string, double>> ScaleList { get; private set; }
static DisplayScale()
{
ScaleList = new List<KeyValuePair<string, double>>()
{
new KeyValuePair<string, double>("No scaling (1's)", 1d),
new KeyValuePair<string, double>("Thousands (1,000's)", 1000d),
new KeyValuePair<string, double>("Millions (1,000,000's)", 1000000d),
new KeyValuePair<string, double>("Billions (1,000,000,000's)", 1000000000d)
};
ActiveScaling = ScaleList.First(); // OPTION: could be in per-user config
}
public static double Scale { get { return ActiveScaling.Value; } }
public static KeyValuePair<string, double> ActiveScaling
{
get
{
lock (_lockHandle) return _ActiveScaling;
}
set
{
lock (_lockHandle)
{
_ActiveScaling = value;
var eventCall = ScalingChanged;
if (eventCall != null) eventCall();
}
}
}
}
字段定义为
// resource
<inf:ScaleConverter x:Key="ScaleConverter" />
// field
<igDP:Field Name="Deposit" Converter="{StaticResource ScaleConverter}">
最佳答案
如果你有一个 collectionview 而不是简单地调用它的 Refresh()。
public class YourViewModel
{
private ObservableCollection<YourDataClass> yourColl;
public void YourViewModel()
{
yourColl = new ObservableCollection<YourDataClass>();
YourCollectionView = CollectionViewSource.GetDefaultView(yourColl);
DisplayScale.ScalingChanged += () => YourCollectionView.Refresh();
}
var ICollectionView yourCollView;
public ICollectionView YourCollectionView
{
get { yourCollView; }
set {
yourCollView = value;
RaisePropertyChanged("YourCollectionView");
}
}
}
关于c# - 导致 xamDataGrid 重新绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8374694/
美好的一天! 我有数据源,它是 100% 填充的。我敢肯定,因为当 AutoGenerateFields 属性设置为 True 时,所有可用数据都会被接收并成功显示。但是,我真正需要实现的是只显示固定
我有 Infragistics XamDataGrid,其中有几列以百分比显示数据。 现在我希望这些列将值显示为百分比,将背景显示为 2 色渐变,其中第一种颜色将绑定(bind)到百分比值,而第二种颜
我正在尝试更改 xamDataGrid 中过滤记录的背景颜色。 我试过了 按照 Infragistics 论坛上的建议,以及 但它们都不起作用,我的过
我正在尝试在 MVVM 体系结构中实现 XamDataGrid 列可见性,但它似乎不起作用。 我正在执行以下操作: 为未绑定(bind)的字段添加 Visiblility 属性 - 在我的 View
我需要能够支持 XamDataGrid,它在设计时不会有一定数量的列。例如,应用程序将运行,从服务器获取一些数据并创建一些对象。根据服务器的响应,每次运行应用程序时我可能有不同数量的对象。 这是我的意
我有一种情况,我将 XamDataGrid 的 DataSource 设置为 ViewModel 列表。因此,我的 XamDataGrid 预计会有多行。我想将给定单元格的可编辑性绑定(bind)到单
好的,我花了 2 天时间试图弄清楚如何做到这一点,并且到目前为止已经获得了“失败”的分数。 设计是这样的: ViewModel 类公开了一个名为 People 的公共(public) Observab
现在我正在尝试将 WPF DataGrid 的 RowDetails 功能之类的功能实现到 XamDataGrid 中。我尝试做的事情(到目前为止失败了): 1.) 替换 ExpandableFiel
我们有一个 Infragistics xamDataGrid将 DataSource 绑定(bind)到 BindingList。我们通过标题在组上设置了一些自定义文本,每次添加或删除项目时都需要重置
我使用 XamDataGrid 来显示标题名称非常长的表格。 header 名称最重要的部分是它的后缀。 有什么方法可以配置列标题,当列宽小于文本大小时,我会看到后缀作为标题? 例子: 要求的结果:
我有一个 multiBinding 效果很好, 我希望能够对特定列进行排序,它显示 w:width、h:height 据我所知,我需要构建一个自定义 IComparer 类来进行比较。 这是我的 XA
我正在开发一个包含许多基础架构 XamDataGrid 的应用程序。我想至少为它们提供复制到剪贴板的能力。这可以在每个网格的 XAML 中轻松实现,方法是:
我需要一种方法让 View 模型指示 View 上的 XamDataGrid 以最少的麻烦重新读取和重新绘制其单元格。我不想弄乱源代码并做一些不可持续的解决方法来引发它的事件(源代码可能会改变)。 为
我的应用程序中有几个 XamDataGrid,我希望它们在用户更改其中的复选框后立即启用各自的“保存”按钮。这目前不会发生,直到我离开单元格或按回车键等,因为单元格仍处于编辑模式。我知道如何使用我在代
我必须创建一个 XamDataGrid,它显示时间范围 x 到 y 的动态列数。因此,我不知道用户会选择多少年来预先创建这些列。 现在通常在 MVVM 中,您只需通过 XamDataGrid 中所需的
我正在使用具有 MVVM 架构的 WPF,我面临的问题是当我向网格添加一条新记录并按回车键时,该记录未设置为事件记录。只有当我点击其他记录,然后再次点击新记录时,它才会更新。 有没有办法可以将新添加
我在带有滚动条的控件中使用 Infragistics XamDataGrid。父控件中还有其他几个控件,我需要能够在父控件中自由滚动。但是,只要鼠标悬停在 XamDataGrid 上,XamDataG
我有一个 MVVM C#/WPF 应用程序。我想将 XamDataGrid 绑定(bind)到我的一个 View 模型,以便用户可以定义他们想要的结果结构 - 将什么列映射到什么变量。 我的核心拥
在我正在处理的应用程序中,如果用户不是管理员,则不得允许他更改数据。但他仍然必须能够对数据进行只读访问。 如果我禁用了网格本身,我将无法滚动浏览记录,也无法使用 infragistics XamDat
我们正在 WPF 应用程序中实现 MVVM 架构。我们想使用 Infragistics XamDataGrid,但是对于在 View 模型层上实现选择更改事件有点迷失。 任何帮助将不胜感激。 我们迫切
我是一名优秀的程序员,十分优秀!