在列表视图中显示所选数据 [英] Display selected data in list view
问题描述
我有两个窗口,一个有访问者列表,另一个用于显示它。如果我选择一个访问者(例如SUNDAR)并显示在另一个页面上如何显示
Xaml访客
< ListView x:名称 = listVisitor ItemsSource = {Binding} HorizontalAlignment = Left 高度 = 582 保证金 = 110,65,0,0 VerticalAlignment = 顶部 Width = 924 Grid.ColumnSpan = 3 / >
< 按钮 内容 = 查看Visi tor 前景 < span class =code-keyword> = white HorizontalAlignment = 左 保证金 = 98,674,0 ,0 VerticalAlignment = Top 宽度 = 320 高度 = 30 背景 = #FF1CA0B7 Grid.ColumnSpan = 2 名称 = ViewBtn 点击 = ViewBtn_Click < span class =code-attribute> / >
代码
<前lang =c#> private void ViewBtn_Click( object sender,RoutedEventArgs e)
{
ViewList dialogBox = new ViewList();`
Nullable< bool> dialogResult = dialogBox.ShowDialog();
}
Xaml Viewlist
< TextBox 名称 = VisitorNo / >
< span class =code-keyword>< TextBox 名称 = 名称 / >
code
private void VisitorNo_TextChanged( object 发送呃,TextChangedEventArgs e)
{
}
private void Name_TextChanged( object sender,TextChangedEventArgs e)
{
}
我已经从访客数据库建立连接
如何在两个文本框中显示?
< blockquote>你需要在PRISM中使用EventAggretators。
在一个窗口中选择一个值后。该值将绑定到视图模型中的属性。
将所选值作为事件对象中的参数发布。
在其他窗口中视图模型侦听/订阅事件并从事件对象参数中获取值。将值绑定到该窗口中所需的依赖项属性,以便该值反映在UI中。
对于视图模型和这种场景之间的通信,我们需要使用evenaggregators。
I have two window,one have list of visitor,another to display it.How to display if I select one visitor(example SUNDAR) and display back on another page
Xaml Visitor
<ListView x:Name="listVisitor" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="582" Margin="110,65,0,0" VerticalAlignment="Top" Width="924" Grid.ColumnSpan="3" />
<Button Content="View Visitor" Foreground="white" HorizontalAlignment="Left" Margin="98,674,0,0" VerticalAlignment="Top" Width="320" Height="30" Background="#FF1CA0B7" Grid.ColumnSpan="2" Name="ViewBtn" Click="ViewBtn_Click" />
Code
private void ViewBtn_Click(object sender, RoutedEventArgs e)
{
ViewList dialogBox = new ViewList();`
Nullable<bool> dialogResult = dialogBox.ShowDialog();
}
Xaml Viewlist
<TextBox Name="VisitorNo"/>
<TextBox Name="Name"/>
code
private void VisitorNo_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void Name_TextChanged(object sender, TextChangedEventArgs e)
{
}
I already make connection from database for Visitor
How to display at both textbox?
You need to use EventAggretators in PRISM.
Once a value is selected in one window.The value will be binded to a property in the view model.
Publish the event with that selected value as a parameter in event object.
In the other window's view model listen/subscribe to the event and get the value from the event object parameter. Bind the value to the required dependency property in that window so that the value gets reflected in UI.
For communication between view models and this kinds of scenarios we need to use evenaggregators.
这篇关于在列表视图中显示所选数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!