【发布时间】:2014-11-01 05:59:42
【问题描述】:
我想更改页面初始化事件中的文本块文本 这是我的 xaml
<ListBox Margin="3,60,1,10" BorderThickness="2" Grid.Row="1" Name="lstAnnouncement" Tap="lstAnnouncement_Tap" Width="476" d:LayoutOverrides="VerticalMargin">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Name="thispanel" Grid.Row="1" Orientation="Horizontal" Height="120" Width="478" >
<StackPanel.Background>
<ImageBrush ImageSource="Images/Text-ALU.png" Stretch="Fill" />
</StackPanel.Background>
<Grid HorizontalAlignment="Left" Width="30" Margin="0,0,0,2" Background="#FF0195D5" Height="118">
<TextBlock x:Name="txtDate" TextWrapping="Wrap">
</TextBlock>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我想在代码隐藏中使用 c# 更改 txtDate.Text,但是在后面的代码中无法访问 txtdate,那么如何实现呢?
【问题讨论】:
-
你试过
txtDate而不是txtdate吗?TextBlock元素当然应该由自动生成的 C# 公开为具有您给它的名称的可访问成员。 -
@PeterDuniho 我犯了同样的错误 - txtDate 包含在他用于
<ListBox.ItemTemplate>的 DataTemplate 中。 -
@furkle:有道理...感谢您指出这一点!
标签: c# xaml windows-phone-8 listbox