使绑定更容易理解

时间:2013-11-16 16:46:12

标签: wpf listview binding styles datatemplate

我用ListView的ItemTemplate创建了样式。

       <Style x:Key = "Thumbnails"
           TargetType = "{x:Type ListView}">

        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Image Width="128"
                           Height="128"
                           Margin="8"
                           Stretch="UniformToFill">
                        <Image.Source>
                            <MultiBinding Converter="{StaticResource UriToBitmapConverter}">
                                <Binding Path="FullPath"/> <!-- how create this binding more understandable -->
                                <Binding RelativeSource="{RelativeSource Mode=Self}" Path="Width"/>
                                <Binding RelativeSource="{RelativeSource Mode=Self}" Path="Height"/>
                            </MultiBinding>
                        </Image.Source>
                    </Image>
                </DataTemplate>
            </Setter.Value>
        </Setter>

    </Style>

在ItemSource属性上,我绑定ObservableCollection<Photos>。照片只包含一个属性FullPath

    <ListView x:Name="Thumbnails"
              Style="{StaticResource Thumbnails}"
              ItemsSource="{Binding Photos,Mode=OneWay, UpdateSourceTrigger=PropertyChanged, IsAsync=True}">

我的问题在于DataTemplate中的多重绑定。

 <Binding Path="FullPath"/>

我想创建这个绑定更容易理解,并告诉我绑定绑定到FullPath的对象集合的属性ListView.ItemSource

有什么想法吗?感谢

0 个答案:

没有答案