[英]WPF Passing an object from one control to another
I am trying to pass an object in one control to another in WPF. 我试图将一个控件中的对象传递给WPF中的另一个控件。 It seems that I am having issue with the binding of the control in the view.
看来我在视图中绑定控件存在问题。
I currently have this: 我目前有这个:
<controls:ConfigControl Grid.Column="0" x:Name="ConfigControl" />
<Label Content="{Binding ConfigControl.JobConfig.JDFPrinterFolder, FallbackValue='didnt work'}"></Label>
<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Column="1" >
<controls:MainControls Margin="0,10,0,0" Grid.RowSpan="2" JobConfig="{Binding ConfigControl.JobConfig}" />
</ScrollViewer>
I am trying to pass the ConfigControl.JobConfig to my MainControls and I added the label to debug and it always results in "didn't work". 我试图将ConfigControl.JobConfig传递给MainControls,并添加了要调试的标签,它始终导致“无法正常工作”。 I'm not sure why it's not working, but a point in the right dirrection would help.
我不确定为什么它不起作用,但是正确的方向会有所帮助。
on my ConfigControl side I have a public object called JobConfig: 在ConfigControl端,我有一个名为JobConfig的公共对象:
public JobConfiguration JobConfig {
get { return _jobConfig; }
set {
_jobConfig = value;
// Call OnPropertyChanged whenever the property is updated
OnPropertyChanged("JobConfig");
}
}
And it get's populated in the constructor for ConfigControl: 然后将其填充到ConfigControl的构造函数中:
public ConfigControl() {
InitializeComponent();
DataContext = this;
LoadSettings(); <--- here
}
I have also debugged to make sure that the settings where there. 我也进行了调试,以确保该设置在那里。
Inside my MainControls I have this: 在我的MainControl中,我有这个:
public JobConfiguration JobConfig {
get { return (JobConfiguration)GetValue(JobConfigProperty); }
set { SetValue(JobConfigProperty, value); }
}
// Using a DependencyProperty as the backing store for JobConfig. This enables animation, styling, binding, etc...
public static readonly DependencyProperty JobConfigProperty =
DependencyProperty.Register("JobConfig", typeof(JobConfiguration), typeof(MainControls), new PropertyMetadata(null));
I have confirmed that the data is set here. 我确认数据已在此处设置。 And everything works in the ConfigControl view.
一切都可以在ConfigControl视图中进行。 Yes I confirmed that JDFPrinterFolder is set.
是的,我确认已设置JDFPrinterFolder。
Try ElementBinding. 尝试使用ElementBinding。
<controls:MainControls Margin="0,10,0,0" Grid.RowSpan="2"
JobConfig="{Binding ElementName=ConfigControl,
Path=JobConfig}" />
<Label Content="{Binding ElementName=ConfigControl,
Path=JobConfig.JDFPrinterFolder,
FallbackValue='didnt work'}" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.