【问题标题】:Name cannot be found in the name scope of ---Error When displaying animation in datagrid名称范围内找不到名称---在datagrid中显示动画时出错
【发布时间】:2011-10-18 09:21:34
【问题描述】:

我有一个显示一些数据的DataGrid。根据某些条件,我需要为DataGrid 中的某些特定单元格设置动画。所以我创建了一个包含标签并给出一些动画的用户控件。 然后我使用模板列在数据网格中显示了这个动画标签。 当我想开始动画时,我将遍历可视化树并找到用户控件并调用StartAnimation 函数。但是这里我收到一个错误

在system.windows.controls.label的名称范围内找不到'lblLabel'名称。

在搜索时,我读到了 herehere。但没有帮助。

当我把它放在窗口上时,我可以为它设置动画。但是当我在数据网格中使用时会出现问题。

谁能解释一下这个问题。 或者有没有更好的方法来为数据网格的单元格设置动画?

【问题讨论】:

    标签: wpf user-controls wpfdatagrid


    【解决方案1】:

    经过一整天的工作,我解决了这个问题。

    以前数据网格的 xaml 代码是这样的:

    <DataGridTemplateColumn Header="MyHeader">    
        <DataGridTemplateColumn.cellTemplate>
            <DataTemplate>
                <my:mycontrol content="{binding mybinding}">
            </DataTemplate>
        </DataGridTemplateColumn.cellTemplate>
    </DataGridTemplateColumn Header="MyHeader">
    

    这里我没有为 MyControl 声明名称 所以换个说法

    <my:mycontrol content="{binding mybinding}"> 
    

    <my:mycontrol x:Name="lblLabel"content="{binding mybinding}">
    

    解决了我的问题。 我希望这对其他人有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-30
      • 1970-01-01
      • 2021-01-24
      相关资源
      最近更新 更多