小编Jun*_*oic的帖子

Tag属性中的WPF数据绑定错误

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:son"
         x:Class="son.SonWindow">
    <Grid x:Name="myGrid">
        <Grid.Tag>
            <Label Content="{Binding ActualWidth, ElementName=myGrid}" />
        </Grid.Tag>
    </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

就像上面的一个简单代码一样,但是绑定找不到Element myGrid.在运行时,错误显示在"输出"窗口中

"System.Windows.Data错误:4:无法找到与引用'ElementName = myGrid'绑定的源.BindingExpression:Path = ActualWidth; DataItem = null;目标元素是'Label'(Name =''); target属性是'内容'(类型'对象')"

我正在使用Visual Studio 2015社区版与.Net Framework 4.5.2.有任何想法吗?先感谢您.

c# data-binding wpf

1
推荐指数
1
解决办法
2039
查看次数

标签 统计

c# ×1

data-binding ×1

wpf ×1