作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个这样的用户控件:
<UserControl x:Class="MySample.customtextbox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="20" d:DesignWidth="300">
<Grid>
<TextBox x:Name="Ytextbox" Background="Yellow"/>
</Grid>
</UserControl>
<CT:customtextbox Text="{binding mypropertyinviewmodel}"/>
DependencyProperty
对于我的控件,直到我可以将我的 View 模型中的属性绑定(bind)到它,所以我为我的控件定义了一个依赖属性,如下所示:
public static readonly DependencyProperty InfoTextProperty =
DependencyProperty.Register("InfoText", typeof(string), typeof(customtextbox), new FrameworkPropertyMetadata(false));
public string InfoText
{
get { return (string)GetValue(InfoTextProperty);}
set
{
SetValue(InfoTextProperty, value);
}
}
Error 1 Cannot create an instance of "customtextbox".
最佳答案
new FrameworkPropertyMetadata(false)
string
的默认值属性(property)给
false
(当然是
bool
)。
TextBox
没有绑定(bind),并且您尝试设置未在创建实例的位置注册的属性),但对于那些您应该搜索 SO。
关于c# - 如何将我的用户控件内容控件中的属性绑定(bind)到我的 View 模型中的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7953437/
我是一名优秀的程序员,十分优秀!