WPF绑定实体框架
本文关键字:框架 实体 绑定 WPF | 更新日期: 2023-09-27 18:15:46
我将实体对象绑定到网格控制
{
InitializeComponent();
gridControl1.DataContext = from q in myEnt.item
from b in myEnt.item_type
where q.item_type_fk == b.item_type_id
select new { q.item_name, q.item,m_type};
}
其工作良好。我想在单击网格控件中的行时在文本框中显示相关数据。我该怎么做?我试过这个:
<TextBox Name="TextBox3" Text="{Binding Path=item_name}"/>
不起作用。
试试这个(你需要告诉TextBox在哪里可以找到item_name
(:
<TextBox Name="TextBox3"
Text="{Binding ElementName=gridControl1, Path=SelectedItem.item_name}"/>
编辑:
gridControl1
似乎是一个没有SelectedItem
属性(?(的DevExpress GridControl
。根据这篇支持文章,通过数据绑定更改所选项目,此绑定可能会起作用(TableView.FocusedRow
(:
<TextBox Name="TextBox3"
Text="{Binding ElementName=tableView1, Path=FocusedRow.item_name}" />
<dxr:DXRibbonWindow
x:Class="Eszkoz.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Eszkoz"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
xmlns:dxbh="http://schemas.devexpress.com/winfx/2008/xaml/bars/internal"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxd="http://schemas.devexpress.com/winfx/2008/xaml/docking"
Title="DXApplication" Height="700" Width="1100"
SnapsToDevicePixels="True" UseLayoutRounding="True"
dx:ThemeManager.ThemeName="Office2013" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid">
<dxr:DXRibbonWindow.Resources>
<dx:EntitySimpleDataSource x:Key="EntitySimpleDataSource" ContextType="local:eszkozEntities" dx:DesignDataManager.DesignData="{dx:DesignDataSettings RowCount=5, UseDistinctValues=True}" Path="eszkoz" />
</dxr:DXRibbonWindow.Resources>
<dxb:BarManager x:Name="barManager" dxbh:BlendHelperForBarsAndRibbon.IsDesignControl="true">
<DockPanel>
<dxd:DockLayoutManager x:Name="dockLayoutManager">
<dxd:LayoutGroup>
<dxd:LayoutPanel ItemWidth="200" Caption="Navigation" Padding="1">
<dxg:GridControl AutoPopulateColumns="True" Name="gridControl1" ItemsSource="{Binding}">
<dxg:GridControl.View>
<dxg:TableView Name="tableView1" ShowTotalSummary="True" />
</dxg:GridControl.View>
</dxg:GridControl>
</dxd:LayoutPanel>
<dxd:LayoutGroup Orientation="Vertical" ItemWidth="4*">
<dxd:LayoutPanel Caption="MainView" ItemHeight="3*">
<dxd:LayoutGroup Orientation="Vertical">
<dxd:LayoutControlItem Caption="Layout Item">
<TextBox Height="23" Name="TextBox3" Width="100" Margin="2" HorizontalAlignment="Left" Text="{Binding ElementName=gridControl1, Path=SelectedItem.item_name}"/>
</dxd:LayoutControlItem>
</dxd:LayoutGroup>
</dxd:LayoutPanel>
<dxd:LayoutPanel Caption="DetailView" ItemHeight="2*"></dxd:LayoutPanel>
</dxd:LayoutGroup>
</dxd:LayoutGroup>
</dxd:DockLayoutManager>
</DockPanel>
</dxb:BarManager>