我有这些保存来自hold服务的信息的文本框。我有一个收集信息的类,当我想要查看它时,它工作得很好。我想从与desc绑定的Textblock中收集一段信息,但是由于我的textbox技术上不存在,除非用户单击一个按钮,所以我不能调用Textbox来收集它的信息。有没有办法做到这一点?
下面是我的代码
<ListView x:Name ="View" >
<ListView.ItemTemplate >
<DataTemplate>
<Grid>
<StackPanel>
<TextBlock Text="{Binding title}"></TextBlock>
<TextBlock Text="{Binding location}"></TextBlock>
<TextBlock Text="{Binding date}"></TextBlock>
<TextBlock
x:Name="desc_text"
Text="{Binding desc}"></TextBlock>
<Button
x:Name ="website"
HorizontalAlignment="Right"
FontFamily="Segoe MDL2 Assets"
Content=""
Click="website_Click"></Button>
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>我的news服务返回一些新闻,所以StackPanel有时会重复执行,每次都有不同的信息(这就是我想要的),以防万一
发布于 2016-04-15 23:10:15
可能还有其他方法可以做到这一点,但最简单的方法是:你的动态文本块必须在后台代码中动态绑定,你可以在创建它之后立即这样做。如下所示:
Binding b = new Binding("color1"); // color1 is the property you are binding to
b.Source = bindedobjectthat-has-a-color1property-to-bind-to;
b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
item.SetBinding(Label.BackgroundProperty, b); // Label.BackgroundProperty is the property receiver of this binding您将不得不实现INotifyPropertyChanged。
https://stackoverflow.com/questions/36648983
复制相似问题