本文介绍了具有单个或两个属性数据的TextBlock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面中,有一个按钮,如下图所示.

In my page I have a button as in the image below.

按钮上的文字来自Place类的两个属性,即Place.address1和Place.address2.

The button has text which comes from two properties of a class Place i.e Place.address1 and Place.address2.

我正在考虑通过执行自定义TextBlock控件并将其添加为Button Content来实现它.我考虑实现TextBlock,因为它可以在我的应用程序中的许多其他地方使用.

I am thinking of implementing it by doing a custom TextBlock control and add the TextBlock as the Button Content. I thought of implementing a TextBlock as it can be used in many other places in my application.

如上图所示:

1.Button 1具有单个属性绑定,即Place.address1,并且字体大小很大.

1.Button 1 has single property bound that is Place.address1 and the fontsize is big.

2.按钮2具有两个属性data&place.address1,并且在下一行中,具有address2的Place.address2应该始终在下一行中.

2.Button 2 has two properties data Place.address1 and in next line Place.address2 with address2 should always be in nextline.

如何在TextBlock中实现相同的目标.

How can I achieve the same in TextBlock.

请帮助.

推荐答案

您应该使用UserControls而不是继承TextBlock控件.只需创建两个新的用户控件即可:一个控件带有大字体的文本块,另一个控件带有包含两个文本块的堆栈面板.

You should be using UserControls instead of inheriting TextBlock control. Simply create new two new user controls: one with textblock with big font and another with stack panel containing two textblocks.

然后,您可以直接使用此类用户控件,即替换为TextBlock,也可以将其放在Button(或任何其他控件)中.

You can then use such user control directly i.e. as a TextBlock replacement or you can put it inside a Button (or any other control).

欢呼


这篇关于具有单个或两个属性数据的TextBlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 23:46