栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

WPF用户控件中的数据绑定

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

WPF用户控件中的数据绑定

如果查看输出窗口,则应该看到绑定异常。

您遇到的问题如下:在用户控件中,您将标签绑定到用户控件的DP
ProtocolNumber,而不是

DataContext
,因此您必须在绑定中添加例如元素名称。

<UserControl Name="MainOptionsPanel"    x:Class="ExperienceMainControls.MainControls"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    x:Name="uc"    ><Label Height="Auto" Name="numberLabel">Protocol:</Label><Label Content="{Binding Path=ProtocolNumber, ElementName=uc}" Name="protocolNumberLabel"/>(...)</UserControl>

编辑:清除一些事情,如果您更改MainWindow中的绑定,您的usercontrol也将起作用。但是您必须使用RelativeSource绑定到MainWindow的DataContext。

    <expControl:MainControls ProtocolNumber="{Binding Path=Number, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" />


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/447162.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号