使用多重绑定的字符串格式?
我正在尝试使用 Label 控件在 XAML 中显示字符串。以下是我的 XAML 代码:
<Label Height="28" HorizontalAlignment="Left" Margin="233,68,0,0" Name="label13" VerticalAlignment="Top">
<Label.Content>
<MultiBinding StringFormat="{}{0} x {1}">
<Binding Path="Width" />
<Binding Path="Height" />
</MultiBinding>
</Label.Content>
宽度和高度是我的电影类的两个属性。 我希望标签显示:“宽度 x 高度”例如。 800×640 然而标签控件仍然是空的。任何帮助表示赞赏。 我想在不使用转换器的情况下执行此操作。
我通过使用 TextBlock 而不是 Label 修改了我的 xaml。但它仍然不会填充显示输出。
<TextBlock Height="28" HorizontalAlignment="Left" Margin="233,68,0,0" Name="label13" VerticalAlignment="Top">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} x {1}">
<Binding Path="Width" />
<Binding Path="Height" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
I'm trying to display a string in XAML using Label control. Following is my XAML code :
<Label Height="28" HorizontalAlignment="Left" Margin="233,68,0,0" Name="label13" VerticalAlignment="Top">
<Label.Content>
<MultiBinding StringFormat="{}{0} x {1}">
<Binding Path="Width" />
<Binding Path="Height" />
</MultiBinding>
</Label.Content>
Width and Height are two properties of my class Movie.
I want the label to display : "Width x Height" ex. 800 x 640
However the label control remains empty. Any help is appreciated.
I WANT TO DO THIS WITHOUT USING A CONVERTER.
I have modified my xaml by using a TextBlock instead of Label. But still it wont populate display the output.
<TextBlock Height="28" HorizontalAlignment="Left" Margin="233,68,0,0" Name="label13" VerticalAlignment="Top">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} x {1}">
<Binding Path="Width" />
<Binding Path="Height" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在尝试将字符串绑定到对象。但 StringFormat 要求其目标是字符串类型。
尝试在标签内容中放入 TextBlock 并将数据绑定到它
编辑
您的类 Movie 必须实现 INotificationPropertyChanged 接口,并且您的两个属性必须使用其属性名称引发属性更改事件!
希望这有帮助
you are trying to bind a string to an object. But StringFormat requires its target to be a string type.
try putting a TextBlock in your label content and bind your data to it
EDIT
your class Movie must implement the INotificationPropertyChanged interface and your two properties must raise the property changed event with their proprty names!
hope this helps