C# 从LINQ查询填充文本块(Web服务)
我已经编写了一个Web服务,它允许我从SQL数据库中提取信息,并在我的通用Windows应用程序中显示这些信息。目前,我正在列表框中显示此信息。我想在3个单独的文本块中显示这些信息,我不确定如何实现这一点。。。这是我目前拥有的可以正常工作的功能,但正在将其放在列表框中: 网络服务C# 从LINQ查询填充文本块(Web服务),c#,wpf,linq,xaml,textblock,C#,Wpf,Linq,Xaml,Textblock,我已经编写了一个Web服务,它允许我从SQL数据库中提取信息,并在我的通用Windows应用程序中显示这些信息。目前,我正在列表框中显示此信息。我想在3个单独的文本块中显示这些信息,我不确定如何实现这一点。。。这是我目前拥有的可以正常工作的功能,但正在将其放在列表框中: 网络服务 [OperationContract] List<TBL_My_Info> FindInfo(string uid); public List<TBL_My_Info> FindInfo
[OperationContract]
List<TBL_My_Info> FindInfo(string uid);
public List<TBL_My_Info> FindInfo(string uid)
{
DataClasses1DataContext context = new DataClasses1DataContext();
var res = from r in context.TBL_My_Info where r.User_Name == uid select r;
return res.ToList();
}
基本上,我想问的是,我怎样才能让3条信息显示在3个单独的文本块中,而不是在一个列表框中
感谢使用绑定的示例:
//this is the backing store property
public static readonly DependencyProperty ListBoxInfoProperty =
DependencyProperty.Register("ListBoxInfo", typeOf(ObservableCollection<Tbl_my_Info>), typeof(thisControlType));
//this is the CLR Wrapper
public ObservableCollection<Tbl_my_Info> ListBoxInfo {
get{return (ObservableCollection<Tbl_my_Info>)GetValue(ListBoxInfoProperty);}
set{SetValue(ListBoxInfoProperty,value);}
您刚刚使XAML能够绑定到此代码
现在在XAML中
<ListBox Height="500" HorizontalAlignment="Left"
Margin="8,47,0,0"
ItemsSource = "{Binding ListBoxInfo}"
Name="listBoxInfo" VerticalAlignment="Top" Width="440">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Title}" FontSize="14" TextWrapping="Wrap"/>
<TextBlock Text="{Binding Description}" FontSize="14" TextWrapping="Wrap"/>
<TextBlock Text="{Binding Name}" FontSize="14" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
试一试……试试listBoxInfo.DataContext=res;但实际上,你应该考虑绑定方法。你能提供一个绑定方法的例子吗,我愿意接受任何建议。不以任何特定方式出售
//this is the backing store property
public static readonly DependencyProperty ListBoxInfoProperty =
DependencyProperty.Register("ListBoxInfo", typeOf(ObservableCollection<Tbl_my_Info>), typeof(thisControlType));
//this is the CLR Wrapper
public ObservableCollection<Tbl_my_Info> ListBoxInfo {
get{return (ObservableCollection<Tbl_my_Info>)GetValue(ListBoxInfoProperty);}
set{SetValue(ListBoxInfoProperty,value);}
DataContext = this;
<ListBox Height="500" HorizontalAlignment="Left"
Margin="8,47,0,0"
ItemsSource = "{Binding ListBoxInfo}"
Name="listBoxInfo" VerticalAlignment="Top" Width="440">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Title}" FontSize="14" TextWrapping="Wrap"/>
<TextBlock Text="{Binding Description}" FontSize="14" TextWrapping="Wrap"/>
<TextBlock Text="{Binding Name}" FontSize="14" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>