【发布时间】:2015-01-05 11:46:35
【问题描述】:
我正在编写一个 Windows Phone 8.1 Silverlight 应用程序。我做了一个用户控件 NotificationsIconUserControl。它只包含一个 BELL/ALARM 图标和文本块来显示未读通知的数量。
我想从 mainpage.xaml 更新这个文本块文本
如何做到这一点?
我尝试使用usercontrol expose properties,但结果恰恰相反。还尝试了this question 的帮助。如何使用依赖属性。请编辑以下代码:
用户控件 XAML:
<Grid x:Name="LayoutRoot"
Background="Transparent"
Height="Auto"
Width="Auto">
<Image
Name="Alarm_Icon"
Source="/Images/Status/Notification_Icon_1.png">
</Image>
<Ellipse
Name="Counter_Icon"
Height="45"
Width="45"
Margin="60,14,-6,50"
StrokeThickness="0"
Fill="{StaticResource DefaultTheme_IndianRedColor}">
</Ellipse>
<TextBlock
Name="Counter_Label"
Foreground="{StaticResource DefaultTheme_LightColor}"
FontSize="30"
HorizontalAlignment="Center"
VerticalAlignment="Center"
TextAlignment="Center"
Margin="75,20,8,58"/>
</Grid>
主页 XAML 部分:
xmlns:MyUserControls="clr-namespace:Project.Custom.UserControls">
主页 .cs 部分:
private void ConfigureNotificationsIcon()
{
int NotificationsCounter = 4;
NotificationsIconUserControl NotificationsIconUserControlObject = new NotificationsIconUserControl();
NotificationsIconUserControlObject.Counter_Label.Text = NotificationsCounter.ToString();
}
【问题讨论】:
标签: xaml windows-phone-8 user-controls