希望这将是一个非常简单的答案,我只是没有看到我认为的树木的谚语.
我有一个DataGridCell样式,我想将单元格的内容绑定到图像的source属性,这是我目前使用的XAML:
<Style x:Key="DataGridImageCellStyle" TargetType="{x:Type toolkit:DataGridCell}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type toolkit:DataGridCell}">
<Border Background="Transparent"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="0"
SnapsToDevicePixels="True">
<Image Source="{Binding RelativeSource={RelativeSource AncestorType=toolkit:DataGridCell}, Path=Content}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
请注意,目前我正在将图像源绑定到内容..这不起作用,我也尝试过Value,这不起作用!
所以我的问题是,很好,很简单..用于将单元格的内容放入此图像的source属性的正确绑定是什么?
提前致谢!
皮特
是的,它是另一个 .net正则表达式问题:)(请原谅实际问题导致的长华夫饼干)
我允许用户使用简单的日期/时间宏快速输入日期(他们不想要日期选择器)
例如,他们可以输入:
d +1d -2h
这将为他们提供今天日期的日期时间字符串,加上一天,减去两个小时.
无论如何我已经创建了一个正则表达式来匹配这些工作正常(可能不是最好的方法,但它的工作原理!):
\b[DTdt]( *[+-] *[1-9][0-9]* *[dDhHmMwW])*\b
因为您可能已经猜到我正在使用正则表达式来验证这些条目,然后再解析它们以计算生成的日期时间.起初我使用了类似的东西:
Regex rgxDateTimeMacro = new Regex(@"\b[DTdt]( *[+-] *[1-9][0-9]* *[dDhHmMwW])*\b");
if(rgxDateTimeMacro.isMatch(strInput)){
...string passes...
}
Run Code Online (Sandbox Code Playgroud)
然后我很快意识到,如果传递的字符串中有任何匹配,则isMatch返回true ,
d +1d +1
将返回true ^ __ ^
所以我改变了它做这样的事情:
Regex rgxDateTimeMacro = new Regex(@"\b[DTdt]( *[+-] *[1-9][0-9]* *[dDhHmMwW])*\b");
MatchCollection objMatches = rgxDateTimeMacro.Matches(strInput);
if (objMatches.Count > 0)
{
// to pass.. we need a match which is the same length as the input string...
foreach (Match m in objMatches)
{
if (m.Length …Run Code Online (Sandbox Code Playgroud)