C# 从另一个框架导航回后未设置运行元素文本属性
我试图根据从dot net中的服务获取的记录数设置Run元素的text属性,当我最初在主页上时,这些值设置正确,但当我导航到另一个页面并返回主页时,该属性显示该值是使用add/quick watch设置的,但它不会显示在UI上。 下面是相同的代码C# 从另一个框架导航回后未设置运行元素文本属性,c#,xaml,windows-store-apps,C#,Xaml,Windows Store Apps,我试图根据从dot net中的服务获取的记录数设置Run元素的text属性,当我最初在主页上时,这些值设置正确,但当我导航到另一个页面并返回主页时,该属性显示该值是使用add/quick watch设置的,但它不会显示在UI上。 下面是相同的代码 if (lstTabIndex != 0) { if (string.IsNullOrEmpty(msgCount.Text)) totalMessages = query.Count(); else totalM
if (lstTabIndex != 0)
{
if (string.IsNullOrEmpty(msgCount.Text))
totalMessages = query.Count();
else
totalMessages = query.Count() + Convert.ToInt32(msgCount.Text);
msgCount.Text = Convert.ToString(totalMessages);
}
TextBlock txtBlockObject = (TextBlock)lstTabs.FindName("tabMessage");
txtBlockObject.Inlines.Remove(runElementObj);
runElementObj = null;
// Create a new instance of run element and add it to the text block
runElementObj = new Run();
runElementObj.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
runElementObj.FontWeight = FontWeights.ExtraBold;
txtBlockObject.Inlines.Add(runElementObj);
下面是xaml代码
<ListView x:Name="lstTabs" ItemContainerStyle="{StaticResource ListViewItemStyle}" IsActiveView="True" Background="#FFC0A789" BorderBrush="Blue" SelectionChanged="lstTabls_SelectionChange" FontSize="25" SelectionMode="Single" Margin="0,0,0,0" Grid.ColumnSpan="2">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<TextBlock x:Name="tabMessage" TextAlignment="Center" VerticalAlignment="Center" FontSize="25" Grid.Column="0" Width="Auto" Height="34" >
Message
<Run x:Name="msgCount" Foreground="Red" FontWeight="ExtraBold"></Run>
</TextBlock>
<TextBlock x:Name="tabTimeTracker" TextAlignment="Center" Grid.Column="1" Width="Auto" FontSize="25" RenderTransformOrigin="0.5,0.5" >
TimeTracker
</TextBlock>
</ListView>
在此方面的任何帮助都将不胜感激
提前感谢好的,我得到了一个有点迂回的解决方案 我在OnNavigatedTo重写函数中动态添加和删除了一个run元素,它的工作方式正是我所希望的。但我不知道为什么正常的方式不起作用。 下面是相同的代码
if (lstTabIndex != 0)
{
if (string.IsNullOrEmpty(msgCount.Text))
totalMessages = query.Count();
else
totalMessages = query.Count() + Convert.ToInt32(msgCount.Text);
msgCount.Text = Convert.ToString(totalMessages);
}
TextBlock txtBlockObject = (TextBlock)lstTabs.FindName("tabMessage");
txtBlockObject.Inlines.Remove(runElementObj);
runElementObj = null;
// Create a new instance of run element and add it to the text block
runElementObj = new Run();
runElementObj.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
runElementObj.FontWeight = FontWeights.ExtraBold;
txtBlockObject.Inlines.Add(runElementObj);
我不理解在Listview中运行的原理。你也可以把它放在外面,然后试着做你想做的事情。我已经把列表视图的样式设计成一个选项卡控件,我想在用户在另一个选项卡上时显示作为通知接收的消息数。