Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.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
将XAML绑定转换为C#_C#_Xaml_Binding_Code Behind - Fatal编程技术网

将XAML绑定转换为C#

将XAML绑定转换为C#,c#,xaml,binding,code-behind,C#,Xaml,Binding,Code Behind,我正在构建一些动态控件,并希望将以下XAML转换为C# 上述内容构成了动态构建的边界控件的一部分,我希望对其进行设置,使其与动态构建的网格具有相同的高度 请问我该怎么做?我发现的所有例子似乎都不完整 谢谢 保罗 修正案。。。好的,这是完整的XAML <Grid x:Name="GridGroup1" HorizontalAlignment="Left" Margin="20,14,0,0" Width="250"

我正在构建一些动态控件,并希望将以下XAML转换为C#

上述内容构成了动态构建的边界控件的一部分,我希望对其进行设置,使其与动态构建的网格具有相同的高度

请问我该怎么做?我发现的所有例子似乎都不完整

谢谢

保罗

修正案。。。好的,这是完整的XAML

<Grid x:Name="GridGroup1" HorizontalAlignment="Left"
                  Margin="20,14,0,0"
                  Width="250"
                  VerticalAlignment="Top">
                <Border BorderThickness="1"
                        CornerRadius="5"
                        Background="{StaticResource PanelBackground}"
                        BorderBrush="{StaticResource PanelBorderBrush}"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Top"
                        Margin="0,8,0,0"
                        Width="250"
                        Height="{Binding ElementName=GridGroup1, Path=ActualHeight}">
                    <Border.Effect>
                        <DropShadowEffect />
                    </Border.Effect>
                </Border>

类似于:

    Binding binding = new Binding();
    binding.Source = GridGroup1;
    binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
    binding.Path = new PropertyPath("ActualHeight");
    MyGridBorder.SetBinding(Border.HeightProperty, binding);

如果没有看到XAML的其余部分,就无法回答这个问题——至少对于讨论中的控件来说是这样。是的,MSDN说的几乎是一样的:@PaulHale别忘了
    Binding binding = new Binding();
    binding.Source = GridGroup1;
    binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
    binding.Path = new PropertyPath("ActualHeight");
    MyGridBorder.SetBinding(Border.HeightProperty, binding);