WPF 压缩此 XAML,将静态字符串分配给绑定

发布于 2024-09-10 03:13:28 字数 644 浏览 2 评论 0原文

我想做的事情可能没有任何实际用途,但为了满足我的好奇心,我们可以将以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我鬧 2024-09-17 03:13:28

我假设出于某种原因您不想定义第二个名为 Two 的静态资源,然后使用与 One 相同的语法...

您应该能够to:

<Binding Source="2"/>

由于 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 with One...

You should be able to:

<Binding Source="2"/>

Since Source is just an Object, this should assign the string "2" to the Source. Haven't checked though as I'm on linux at the moment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文