如何避免文本框中的默认文本?
我有一个文本框,它使用多重绑定 usingStringFormat... 如下所示。 但它显示默认值为 {DependencyProperty.UnsetValue},{DependencyProperty.UnsetValue}
如何避免这种情况?
<StackPanel Orientation="Horizontal">
<TextBlock Width="70" Text="Name:" Margin="5,2,2,2"></TextBlock>
<TextBox Width="160" DataContext="{Binding }" IsReadOnly="True" Margin="2">
<TextBox.Text>
<MultiBinding StringFormat="{}{0},{1}">
<Binding Path="LastName"/>
<Binding Path="FirstName"/>
</MultiBinding>
</TextBox.Text>
</TextBox>
</StackPanel>
请帮我。
I have a textbox, which uses multi-binding usingStringFormat...as shown below.
But it displays the default value as
{DependencyProperty.UnsetValue},{DependencyProperty.UnsetValue}
How to avoid this ?
<StackPanel Orientation="Horizontal">
<TextBlock Width="70" Text="Name:" Margin="5,2,2,2"></TextBlock>
<TextBox Width="160" DataContext="{Binding }" IsReadOnly="True" Margin="2">
<TextBox.Text>
<MultiBinding StringFormat="{}{0},{1}">
<Binding Path="LastName"/>
<Binding Path="FirstName"/>
</MultiBinding>
</TextBox.Text>
</TextBox>
</StackPanel>
Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您绑定的对象出现问题。我刚刚从头开始创建了一个应用程序,其中包含继承自 DependencyObject 的 Person 类。我未设置名字和姓氏属性,但没有看到 DependencyProperty.UnsetValue,而是看到一个空白 TextBox,其中仅包含一个逗号。
(一般来说,无论如何,您都不应该在业务对象上使用依赖属性。坚持使用 INotifyPropertyChanged 可以让您省去很多麻烦。)
将代码发布到您的绑定对象,也许我可以发现问题。
-
-
Something is wrong with the object you are binding to. I just created an application from scratch with a Person class that inherits from DependencyObject. I left the first and last name properties unset and I did not see DependencyProperty.UnsetValue, but rather a blank TextBox with just a comma in it.
(In general, you shouldn't use dependency properties on your business objects anyway. Stick to INotifyPropertyChanged and save yourself a ton of headaches.)
Post the code to your bound object and maybe I can spot the issue.
-
-
只需给出fallbackvalue =“”并查看
如果绑定不成功,即未找到绑定源的路径或值转换器(如果有)失败,则返回DependencyProperty.UnsetValue,然后将目标属性设置为FallbackValue(如果您当然定义了一个)。
just give the fallbackvalue="" and see
If a binding is not successful, i.e. the path to the binding source is not found or the value converter , if any, fails, a DependencyProperty.UnsetValue is returned, then the target property is set to the FallbackValue, if you defined one of course.