如何使用两个TextBlock进行用户控制 [英] How to make user control with two TextBlocks

查看:67
本文介绍了如何使用两个TextBlock进行用户控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拥有这样的用户控件:

I would like to have user control like this:

<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="d"
	x:Class="Test.MyStack"
	d:DesignWidth="128" d:DesignHeight="75">

	<Grid x:Name="LayoutRoot" Background="Transparent">
		<StackPanel HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center" >
			<TextBlock x:Name="Header" TextWrapping="Wrap" Text="Header" HorizontalAlignment="Center" FontSize="18" Margin="0,0,0,2" TextAlignment="Center"/>
			<Border HorizontalAlignment="Center" BorderThickness="4" CornerRadius="8" >
				<Border.BorderBrush>
					<SolidColorBrush Color="{StaticResource PhoneBorderColor}"/>
				</Border.BorderBrush>
				<TextBlock x:Name="TextValue" TextWrapping="Wrap" Text="TextValue" FontSize="24" Margin="0" Padding="10,2,10,6" TextAlignment="Center"/>
			</Border>
		</StackPanel>
	</Grid>
</UserControl>

问题是如何定义"Header.Text"?和"TextValue.Text"将控件添加到Mainpage.xaml文件中时。当我将其插入页面时,只有:< local:MyStack x:Name =" TestStack"余量= QUOT; 0"
Horizo​​ntalAlignment =" Center" VerticalAlignment = QUOT;中心" />就这样。可以在Mainpage.cs中以编程方式完成,但我想在mainpage.xaml文件中完成它。提前谢谢。

The problem is that how can I define the "Header.Text" and "TextValue.Text" when adding the control into Mainpage.xaml file. When I insert it into a page there is only: <local:MyStack x:Name="TestStack" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"/> and thats all. Programmatically in Mainpage.cs it can be done, but I would like to have it done in mainpage.xaml file. Thank you in advance.

推荐答案

你好,


可能这不是准确答案,但你可以轻松控制,

hello ,

May be that's not the accurate answer but you can make its control easily,

转到文本块选择,右键单击它们混合,你会看到一个选项

go to the very textblocks select the, right click on them in blend , you would see an option

" Make Into UserControl"点击它,它将生成用户控件的文件XAML和CS,你可以根据需要更改或管理控制 



希望它对你有用 

"Make Into UserControl" Click on that , it would generate the user control's file XAML and CS and you can change or manage control according to your need 

Hope it works for you 

问候,


这篇关于如何使用两个TextBlock进行用户控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆