के साथ बाध्यकारी के लिए स्रोत नहीं मिल रहा है मुझे नीचे दिए गए कोड से निम्नलिखित त्रुटियां मिलती हैं ... सुनिश्चित नहीं है क्यों (और हाँ, यह सभी 4 उत्पन्न करता है भले ही यह वही 2 बार दोहराया गया हो)। ओह, और यह वैकल्पिक पंक्तियों का प्रभाव उत्पन्न नहीं करता है, भले ही इन त्रुटियों से पहले एक ही कोड पॉप-अप कर रहा था।डब्ल्यूपीएफ डेटा बाइंडिंग त्रुटि: संदर्भ 'रिलेटिवसोर्स FindAncestor'
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=AreRowDetailsFrozen; DataItem=null; target element is 'DataGridDetailsPresenter' (Name=''); target property is 'SelectiveScrollingOrientation' (type 'SelectiveScrollingOrientation')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=HeadersVisibility; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'Visibility' (type 'Visibility')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=AreRowDetailsFrozen; DataItem=null; target element is 'DataGridDetailsPresenter' (Name=''); target property is 'SelectiveScrollingOrientation' (type 'SelectiveScrollingOrientation')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=HeadersVisibility; DataItem=null; target element is 'DataGridRowHeader' (Name=''); target property is 'Visibility' (type 'Visibility')
<UserControl x:Class="MyProject.Views.RegistrationAllView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyProject.Views"
>
<Grid>
<DataGrid Name="TestGrid" Grid.Row="2" Grid.ColumnSpan="2" AutoGenerateColumns="True"
ItemsSource="{Binding Registrations}" SelectedValue="{Binding CurrentRegistration}" IsReadOnly="True" GridLinesVisibility="None"
AlternatingRowBackground="#FFCAC6C6"
>
<DataGrid.RowStyle>
<Style>
<EventSetter Event="DataGridRow.MouseDoubleClick" Handler="TestGrid_MouseDoubleClick" />
</Style>
</DataGrid.RowStyle>
</DataGrid>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MyProject.ViewModels;
using WPFBase;
using WPFBase.ViewModels;
namespace MyProject.Views
{
public partial class RegistrationAllView : UserControl
{
public RegistrationAllView()
{
InitializeComponent();
}
private void TestGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
DependencyObject source = e.OriginalSource as DependencyObject;
RegistrationEntity entity = (RegistrationEntity)TestGrid.CurrentItem;
TabControl TabCollection = (TabControl)UIHelper.TryFindParentControl<TabControl>(this);
RegistrationForm view = new RegistrationForm();
XTabItem tabItem = new XTabItem();
tabItem.Header = String.Format("Registration (#{0})", entity.ID);
tabItem.Content = view;
TabCollection.Items.Add(tabItem);
tabItem.Focus();
AbstractViewModel vm = new RegistrationViewModel(entity);
view.DataContext = vm;
}
}
}
आपके 'आइटम स्रोत 'में ऑब्जेक्ट्स के लिए' DataTemplate' कहां है? –
@ रॉबर्ट रॉसनी: मैंने इसे ऑटो जेनरेट कॉलम पर सेट किया है, इसलिए मुझे वास्तव में डेटा टेम्पलेट की आवश्यकता नहीं है। –