设定一个用户控件NumberTextBox,其中包含Label和TextBox:
<Stackpanel Ori…>
<Label Content = “{Binding ElementName = root, Path=Label}”/>
<TextBox Width=”{Binding ElementName = root,Path=TextWidth}”/>
</Stackpanel>.cs文件中加入两个以来属性,分别为Label和TextWidth,其形式为:#region TextWidth
public static readonly DependencyProperty TextWidthProperty = DependencyProperty.Register(
"TextWidth", typeof(Double), typeof(NumberTextBox)); public Double TextWidth
{
get { return (Double)GetValue(TextWidthProperty); }
set { SetValue(TextWidthProperty, value); }
}
#endregion
Label为string类型
调用形式为<local:NumberTextBox TextWidth=”100” Label=”hello”></…>
但是该绑定就没有成功过,不知道为什么?
<Stackpanel Ori…>
<Label Content = “{Binding ElementName = root, Path=Label}”/>
<TextBox Width=”{Binding ElementName = root,Path=TextWidth}”/>
</Stackpanel>.cs文件中加入两个以来属性,分别为Label和TextWidth,其形式为:#region TextWidth
public static readonly DependencyProperty TextWidthProperty = DependencyProperty.Register(
"TextWidth", typeof(Double), typeof(NumberTextBox)); public Double TextWidth
{
get { return (Double)GetValue(TextWidthProperty); }
set { SetValue(TextWidthProperty, value); }
}
#endregion
Label为string类型
调用形式为<local:NumberTextBox TextWidth=”100” Label=”hello”></…>
但是该绑定就没有成功过,不知道为什么?
解决方案 »
- ◆winform下如何判断datagridview中的新增、删除、修改状态◆
- 字符串转字节问题
- [C# TreeNode与TreeView ]关于载入树形目录问题
- delphi可以做什么开发?
- vs.net2005中的crystalReportView.ReportSource怎么不好用呢?
- 如何把一个FORM里的数字串从第一个数字开始,一个一个传到另一个FORM里?麻烦各位大侠帮忙
- [高分-顶者有分]如何使用TreeView控件实现树节点重命名的功能?
- 高分相送:在[WEB]C#.NET中用JAVASCRIPT调用数据库为什么会出现提示?
- 我将decimal转成字符串后,如果不代小数任会显示个0
- 在GDI的问题,大家请进!
- WPF用C#显示软件正常运行时间
- dev中chartControl控件的用法
或者<NumberTextBox>定义位置有问题?我仿照你提供的信息写了一个概括,没有任何问题的,不是上述问题那把代码贴出来讨论一下吧 <StackPanel>
<local:NumberTextBox x:Name="root" TextWidth="100" Label="hello"></local:NumberTextBox>
<Label Content ="{Binding ElementName = root, Path=Label}"/>
<TextBox Width="{Binding ElementName = root,Path=TextWidth}"/>
</StackPanel> public class NumberTextBox : Control
{
public static readonly DependencyProperty TextWidthProperty = DependencyProperty.Register("TextWidth", typeof(Double), typeof(NumberTextBox));
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register("Label", typeof(string), typeof(NumberTextBox)); public Double TextWidth
{
get { return (Double)GetValue(TextWidthProperty); }
set { SetValue(TextWidthProperty, value); }
}
public string Label
{
get { return (string)GetValue(LabelProperty); }
set { SetValue(LabelProperty, value); }
}
}