设置DataContext时“无法解析TargetName”

时间:2011-09-08 13:12:05

标签: c# silverlight-4.0

我得到了这个例外:
“无法解析TargetName userControl”
当我尝试设置DataContext时。

这是xaml:

<UserControl x:Class="TagCheckView"
         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:System="clr-namespace:System;assembly=mscorlib" 
         mc:Ignorable="d" Margin="3,0">
    <Grid x:Name="LayoutRoot" >
    <VisualStateManager.VisualStateGroups>
        <!-- snip -->
    </VisualStateManager.VisualStateGroups>
    <TextBlock Text="{Binding Tag.Name, Mode=TwoWay, TargetNullValue='Value is Null'}" 
               TextWrapping="Wrap" Foreground="Red"  />
    </Grid>
</UserControl>

抛出异常的代码:

 TagCheckView tagCheckView = new TagCheckView();
 tagCheckView.DataContext = m.ViewModel;  /* boom */

感谢任何关于出错的提示......

0 个答案:

没有答案