有什么想法为什么Google Docs脚本似乎不支持这种简单的RegEx?
foo(?!bar)
我假设Google Apps脚本使用与JavaScript相同的RegEx。不是吗
我这样使用RegEx:
DocumentApp.getActiveDocument().getBody().replaceText('foo(?!bar)', 'hello');
Run Code Online (Sandbox Code Playgroud)
这将产生错误:
ScriptError:无效的正则表达式模式foo(?!bar)
我发现当行的项目包含验证错误时,ContentPresenter用于显示 a 内容的DataGridTemplateColumn会显示默认值。ErrorTemplate我看不到任何直接的方法来阻止这种情况。有任何想法吗?
这是我第一次尝试确保不显示验证错误模板:
<DataGridTemplateColumn Width="70" Header="Enabled" Validation.ErrorTemplate="{x:Null}" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Enabled.Value}"
HorizontalAlignment="Center"
VerticalAlignment="Center" Validation.ErrorTemplate="{x:Null}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellStyle>
<Style >
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
</Style>
</DataGridTemplateColumn.CellStyle>
</DataGridTemplateColumn>
Run Code Online (Sandbox Code Playgroud)

使用 Snoop 我看到该单元格包含一个ContentPresenter显示验证错误的单元格。
我发现只能通过删除数据网格中所有内容呈现器上的错误模板来禁用此功能,如下所示:
<DataGrid.Resources>
<Style TargetType="ContentPresenter">
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
</Style>
</DataGrid.Resources>
Run Code Online (Sandbox Code Playgroud)
有没有办法只影响单个DataGridTemplateColumn?
这篇文章看起来很相似: DataGridCell Validation.ErrorTemplate被忽略
请参阅下面的VS2013更新.
当使用类作为d:DesignInstance暴露a 的类时KeyedCollection<TKey, TItem>,XAML设计器会抱怨以下警告:
提供的泛型参数的数量不等于泛型类型定义的arity.
参数名称:实例化
可以使用以下简单程序重现该问题:
<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Test"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance local:MyClass}" />
namespace Test
{
public partial class MainWindow : Window
{
public MainWindow() { InitializeComponent(); }
}
public class MyClass
{
public KeyedCollection<string, object> SettingsModule { get; private set; }
}
}
Run Code Online (Sandbox Code Playgroud)
我无法为暴露的任何类提供设计时间形状KeyedCollection.
有什么想法在这里发生了什么?
更新:从VS2013开始,设计师处理a的行为KeyedCollection已经改变(尽管仍然没有完全发挥作用).
上面的示例不再生成错误.但是,如果KeyedCollection使用某些类型(如接口)作为TItem以下错误生成:
你调用的对象是空的.
请考虑以下示例:
namespace Test
{
public partial class MainWindow : Window
{
public MainWindow() { …Run Code Online (Sandbox Code Playgroud) 我在使用包含非托管对象的正确处理 Dispose/Finalization 时遇到问题ConcurrentBag。运行下面的代码(通常)会在调用 时产生一个ObjectDisposedException( ) 。Cannot access a disposed object.Object name: 'The ThreadLocal object has been disposed.'.TryTake()
大概在这种情况下,垃圾收集器正在销毁ConcurrentBag调用 A 的终结器之前的内容。ConcurrentBag我原以为只有当它本身实现了终结器时才会出现这种情况。是否存在一种情况,即在终结路径期间永远不应该接触托管对象?
class A : IDisposable
{
private readonly ConcurrentBag<object> _collection = new ConcurrentBag<object>();
public A(string value)
{
if (value == null) throw new ArgumentNullException();
}
~A()
{
Dispose(false);
}
public void Dispose() => Dispose(true);
private void Dispose(bool disposing)
{
if (disposing) {}
object value;
while (_collection.TryTake(out value))
{
// Cleanup value …Run Code Online (Sandbox Code Playgroud)