我有这些文本框,其中包含来自Web服务的信息。我有一个收集信息的课程,然后当我想看到它时,它工作正常。我想要从具有desc绑定的Textblock中收集一条信息,但由于我的文本框技术上不存在,除非用户单击按钮,否则我无法调用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>
我的webservice返回一些新闻,所以StackPanel有时会自我重复,每个都有不同的信息(这就是我想要的),以防必要
答案 0 :(得分:-1)
There might be other ways to do this, but the easiest way imo: Your dynamic textblock has to be binded dynamically in code behind, you can do that right after you create it. Something like this:
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
You will have to implement INotifyPropertyChanged.