Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将对象调用作为参数传递/绑定到UserControl_C#_.net_Wpf - Fatal编程技术网

C# 将对象调用作为参数传递/绑定到UserControl

C# 将对象调用作为参数传递/绑定到UserControl,c#,.net,wpf,C#,.net,Wpf,我有一个名为“DataEntryForm”的主窗口和2个用户控件“Identification”和“SamplingInformation”,它们作为选项卡嵌入主窗口中 我有一个名为Report的对象,它在“Identification”UserControl中调用 <Window x:Class="Frontend_WPF.Forms.DataEntryForm" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presen

我有一个名为
“DataEntryForm”
的主窗口和2个
用户控件
“Identification”和
“SamplingInformation”
,它们作为选项卡嵌入主窗口中


我有一个名为Report的对象,它在
“Identification”
UserControl中调用

<Window x:Class="Frontend_WPF.Forms.DataEntryForm"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Frontend_WPF.Forms.User_Controls"
    mc:Ignorable="d"
    Title="Data Entry"  Width="800" Height="600" WindowStartupLocation="CenterScreen" WindowState="Maximized" WindowStyle="SingleBorderWindow"  >
<Viewbox Stretch="Fill" Margin="0">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="695*" />
        </Grid.RowDefinitions>
        <Viewbox Stretch="Fill">
        <TabControl  HorizontalAlignment="Left" Name="TabControl" VerticalAlignment="Top"  Grid.RowSpan="1" >
            <TabItem Name="ID">
                <TabItem.Header>
                    <TextBlock Name="IDHeader" Text="ID" 
                 ToolTip="IDENTIFICATION"/>
                </TabItem.Header>
                <Grid>
                    <local:Identification x:Name="Identification_UC" />
                </Grid>
            </TabItem>
            <TabItem Name="SamplingInformation">
                <TabItem.Header>
                    <TextBlock Name="SIHeader" Text="SAMPLING INFORMATION" 
                 ToolTip="SAMPLING INFORMATION"/>
                </TabItem.Header>
                <Grid>
                    <local:SamplingInformation x:Name="SamplingInformation_UC" />
                </Grid>
            </TabItem>
        </Viewbox>
    </Grid>
</Viewbox >
我需要将Report对象绑定/调用/传递到
“SamplingInformation”
UserControl

<Window x:Class="Frontend_WPF.Forms.DataEntryForm"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Frontend_WPF.Forms.User_Controls"
    mc:Ignorable="d"
    Title="Data Entry"  Width="800" Height="600" WindowStartupLocation="CenterScreen" WindowState="Maximized" WindowStyle="SingleBorderWindow"  >
<Viewbox Stretch="Fill" Margin="0">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="695*" />
        </Grid.RowDefinitions>
        <Viewbox Stretch="Fill">
        <TabControl  HorizontalAlignment="Left" Name="TabControl" VerticalAlignment="Top"  Grid.RowSpan="1" >
            <TabItem Name="ID">
                <TabItem.Header>
                    <TextBlock Name="IDHeader" Text="ID" 
                 ToolTip="IDENTIFICATION"/>
                </TabItem.Header>
                <Grid>
                    <local:Identification x:Name="Identification_UC" />
                </Grid>
            </TabItem>
            <TabItem Name="SamplingInformation">
                <TabItem.Header>
                    <TextBlock Name="SIHeader" Text="SAMPLING INFORMATION" 
                 ToolTip="SAMPLING INFORMATION"/>
                </TabItem.Header>
                <Grid>
                    <local:SamplingInformation x:Name="SamplingInformation_UC" />
                </Grid>
            </TabItem>
        </Viewbox>
    </Grid>
</Viewbox >

我可以传递对象并在“SamplingInformation”用户控件中使用它,还是有办法将其直接绑定到它?

您可以将
local:Identification
的DataContext绑定到
local:SamplingInformation
以便两个选项卡都代表相同的对象。“我有一个名为Report的对象,在“Identification”中调用“用户控制“。在提供的代码示例上没有这方面的指示。对两个
用户控件使用共享的
数据上下文
?如果您希望能够绑定到
标识
中的相同属性,或者反之亦然,那么仅在
标识
数据上下文
中定义某些属性有什么意义?这听起来像是一个设计缺陷。