在 VS 2010 Express for Windows Phone 中更改文本块 UserControl 上的文本
我在 VS2010 Express for Windows Phone 中创建了具有文本块的 UserControl,并将其添加到 MainPage.xaml 中。但是,我想在代码隐藏或 .xaml 文件中设置文本块上的文本。有人可以向我展示或给出示例或链接吗?提前致谢。
<UserControl x:Class="PhoneApp1.TitleControl"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480">
<Grid x:Name="LayoutRoot">
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,10,28">
<TextBlock x:Name="ApplicationTitle" Style="{StaticResource appTitleStyle}"/>
<Grid Height="45" Style="{StaticResource pageTitleBackgroudStyle}">
<TextBlock x:Name="PageTitle" Margin="9,-7,0,17" Style="{StaticResource pageTitleStyle}"/>
</Grid>
</StackPanel>
</Grid>
这是我的 MainPage.xaml:
<StackPanel x:Name="Titleqq" Grid.Row="0" Margin="12,17,0,28" Grid.ColumnSpan="2">
<local:TitleControl x:name="Title" />
</StackPanel>
I created the UserControl which has textblock in VS2010 Express for Windows Phone and added it on the MainPage.xaml. However, I would like to set the text on the the textblock either in codebehind or .xaml file. Would anyone show or give an example or link to me. Thank in advance.
<UserControl x:Class="PhoneApp1.TitleControl"
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"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480">
<Grid x:Name="LayoutRoot">
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,10,28">
<TextBlock x:Name="ApplicationTitle" Style="{StaticResource appTitleStyle}"/>
<Grid Height="45" Style="{StaticResource pageTitleBackgroudStyle}">
<TextBlock x:Name="PageTitle" Margin="9,-7,0,17" Style="{StaticResource pageTitleStyle}"/>
</Grid>
</StackPanel>
</Grid>
This is my MainPage.xaml:
<StackPanel x:Name="Titleqq" Grid.Row="0" Margin="12,17,0,28" Grid.ColumnSpan="2">
<local:TitleControl x:name="Title" />
</StackPanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编写用户控件时需要注意两件事。
编写一个在用户控件中定义属性的类。
将其绑定到您希望在 Windows Phone 应用程序中公开或设置的属性。
所以你的用户控件最好有,
UserControl.xaml
UserControl.xaml.cs
您在 cs 文件中编写类。将其绑定到您要在应用程序中设置的属性。所以在这种情况下,你会做这样的事情,
现在在你的代码后面编写一个继承自 UserControl 的类并绑定它......
Link1 和 google 上的 msdn Windows Phone UserControl 类。
点击链接->
There are two things to note when writing a usercontrol.
Write a class that defines properties in your usercontrol.
Bind it to the properties that you wish to expose or set in your windows phone application.
So your Usercontrol would Ideally have,
UserControl.xaml
UserControl.xaml.cs
You write your class in cs file. Bind it to the properties that you want to set in your application. So in this case you do something like this,
Now in your code behind write a class that inherits from UserControl and bind it...
Link1 and google on msdn Windows phone UserControl class.
Follow the link->