WPF 压缩此 XAML,将静态字符串分配给绑定
我想做的事情可能没有任何实际用途,但为了满足我的好奇心,我们可以将以下 XAML 中的第二个绑定压缩为 1 行
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource MyConverter}">
<Binding Source="{StaticResource One}"></Binding>
<Binding>
<Binding.Source>
<sys:String>2</sys:String>
</Binding.Source>
</Binding>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
StaticResource One 给我“1”,而 MyConverter 只是连接它获得的所有值。 我正在寻找的是一种以类似于第一个绑定的紧凑格式表达第二个绑定的方法。
There may not be any practical use of what I want to do, but just to satisfy my curiosity can we compact the 2nd binding in the following XAML into 1 line
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource MyConverter}">
<Binding Source="{StaticResource One}"></Binding>
<Binding>
<Binding.Source>
<sys:String>2</sys:String>
</Binding.Source>
</Binding>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
StaticResource One gives me "1" and MyConverter just concatenates all values it gets.
What I am looking for is some way to express the 2nd binding in a compact format like the 1st binding.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设出于某种原因您不想定义第二个名为
Two
的静态资源,然后使用与One
相同的语法...您应该能够to:
由于
Source
只是一个Object
,因此应将字符串“2”分配给Source
。还没有检查过,因为我现在在 Linux 上。I'm assuming there's some reason you don't want to define a second static resource called
Two
and then use the same syntax as withOne
...You should be able to:
Since
Source
is just anObject
, this should assign the string "2" to theSource
. Haven't checked though as I'm on linux at the moment.