ฉันมีปัญหาในการผูกข้อมูลเล็กน้อยใน wpf ฉันมีกล่องข้อความที่สามารถป้อนข้อมูลได้ จากนั้นฉันก็พยายามผูกอินพุตข้อความกับตัวควบคุมผู้ใช้แบบกำหนดเอง สิ่งนี้ใช้ได้กับ usercontrol ภายใน RowDetailsTemplate แต่ไม่ใช่ใน CellTemplate สำหรับแต่ละวัตถุใน CellTemplate ฉันได้รับผลลัพธ์ข้อผิดพลาดนี้:
ข้อผิดพลาด System.Windows.Data: 4: ไม่พบแหล่งที่มาสำหรับการผูกกับการอ้างอิง 'ElementName=ScaleTextBox' BindingExpression:Path=ข้อความ; รายการข้อมูล=null; องค์ประกอบเป้าหมายคือ 'แผนภูมิ' (ชื่อ = ''); คุณสมบัติเป้าหมายคือ 'MaxValue' (ประเภท 'Int32')
รหัสของฉันมีลักษณะเช่นนี้:
XAML
<ToolBarTray ToolBarTray.IsLocked="True" DockPanel.Dock="Top" Height="25">
<ToolBar Name="ButtonBar" >
<TextBox Height="23" Name="ScaleTextBox" Width="120" Text="400"/>
</ToolBar>
</ToolBarTray>
<DataGrid ItemsSource="{Binding Path=Items}" AutoGenerateColumns="False" IsReadOnly="True" RowHeight="25" RowDetailsVisibilityMode="VisibleWhenSelected">
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" >
<my:UserControl ItemsSource="{Binding Path=Samples}" MaxValue="{Binding ElementName=ScaleTextBox, Path=Text}"/>-->
</StackPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
<DataGrid.Columns>
<DataGridTemplateColumn MinWidth="150" Header="Chart" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<my:UserControl ItemsSource="{Binding Path=Samples}" MaxValue="{Binding ElementName=ScaleTextBox, Path=Text}"/><!-- this is the problem -->
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
C#
public static readonly DependencyProperty MaxValueProperty = DependencyProperty.Register("MaxValue", typeof(int), typeof(Chart), new FrameworkPropertyMetadata(MaxValuePropertyChanged));
private static void MaxValuePropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
Console.WriteLine(e.NewValue);
}
ฉันทำอะไรผิด?