English 中文(简体)
XAML, binding Width and Height Property to same property of other control
原标题:XAML, binding Width and Height properties to the same properties of other control

我试图产生反省的效果,但我不得不硬化一些价值观,否则,我的工作是巨大的。 这是我的XAML:

 <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="60"/>
        <RowDefinition />
        <RowDefinition Height="80"/>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="1" VerticalAlignment="Center">
        <UserControl x:Name="CurrentPresenter" />
        <Border Width="500" Height="200" >
            <Border.Background>
                <VisualBrush Visual="{Binding ElementName=CurrentPresenter}" >
                    <VisualBrush.Transform>
                        <TransformGroup>
                            <ScaleTransform ScaleX="1" ScaleY="-1" CenterX="500" CenterY="99" />
                        </TransformGroup>
                    </VisualBrush.Transform>
                </VisualBrush>
            </Border.Background>
            <Border.OpacityMask>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,0.6">
                        <GradientStop Offset="-0.6" Color="Black"></GradientStop>
                        <GradientStop Offset="0.6" Color="Transparent"></GradientStop>
                    </LinearGradientBrush>
                </Border.OpacityMask>
        </Border>
    </StackPanel>
</Grid>

I ve试图通过Width=“500”Hala=<200>,通过<代码>Width="{具有约束力的 ElementName=CurrentPresenter, Path=Width}"和Hal=>{具有约束力的ElementName=CurrentPresenter, Path=Hal}”,但似乎没有工作。

Wha错了该法典吗?

UPDATE: 如果我在此提出Width和Height:

<UserControl x:Name="CurrentPresenter" Height="200" Width="500" />

它按预期运作。 然而,如果我把这些价值观列入用户大会,它就没有工作。 任何想法?

问题回答

不是对用户目录的Hight and Width属性的约束,而是由您尝试对<代码>H 8,和的特性(<代码>Border>>的代谢/代码>和ActualWidth的用户群特性具有约束力?

<Border 
 Width="{Binding ElementName=CurrentPresenter, Path=ActualWidth}"
 Height="{Binding ElementName=CurrentPresenter, Path=ActualHeight}" >

改变观点的道路! 纽约总部





相关问题
How to bind a TabControl to an ObservableCollection in XAML

I have the following line of code in my code-behind class. TabControl.ItemsSource = ((MainWindowViewModel)DataContext).TabItemViewModels; I would like to move this to the XAML file. In brief, ...

Bind to ancestor of adorned element

Here is the case: <DataTemplate x:Key="ItemTemplate" DataType="local:RoutedCustomCommand"> <Button Command="{Binding}" Content="{Binding Text}" ...

FlowDocument Force a PageBreak (BreakPageBefore)

I m using C# to create a FlowDocument and fill it with data within a table. Example: FlowDocument flowDoc = new FlowDocument(); Table table1 = new Table(); flowDoc.Blocks.Add(table1); table1....

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF TreeView binding through XAML

So I have a class structure like this Store Owner Cashier List of Products Product Name Price List of Vendors Company Name Contact Name So there are 4 ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...