簡體   English   中英

FlipView中RowDefinition的綁定與FlipView本身的綁定不同

[英]Binding of RowDefinition in FlipView different then binding of FlipView itself

“ MyGrid”具有具有三個公共屬性的DataContext (在后面的代碼中分配):

  • '圖片'
  • 'H1'
  • 'H2'

以下代碼的問題是,與“ h1”和“ h2”的綁定設置為“圖像”集合的元素,但應將其設置為與“ MyGrid”的綁定。

我的密碼

<Grid x:Name="MyGrid">
    <FlipView ItemsSource="{Binding Images}">
        <FlipView.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="{Binding h1}"></RowDefinition>
                        <RowDefinition Height="{Binding h2}"></RowDefinition>
                    </Grid.RowDefinitions>

                    <Image Grid.Row="0" Source="{Binding}"></Image>
                    <TextBlock Grid.Row="1" Text="AAA"></TextBlock>
                </Grid>
            </DataTemplate>
        </FlipView.ItemTemplate>
    </FlipView>
</Grid>

我應該如何更改“ h1”和“ h2”綁定?

謝謝!

使用ElementName指定綁定源:

 <Grid x:Name="MyGrid">
        <FlipView ItemsSource="{Binding Images}">
            <FlipView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="{Binding ElementName=MyGrid, Path=DataContext.h1}"></RowDefinition>
                            <RowDefinition Height="{Binding ElementName=MyGrid, Path=DataContext.h2}"></RowDefinition>
                        </Grid.RowDefinitions>

                        <Image Grid.Row="0"
                               Source="{Binding}"></Image>
                        <TextBlock Grid.Row="1"
                                   Text="AAA"></TextBlock>
                    </Grid>
                </DataTemplate>
            </FlipView.ItemTemplate>
        </FlipView>
    </Grid>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM