none
WPF中绑定的图片固定是6个,如果不够6个如何显示默认图? RRS feed

答案

  • Hi,

    >> WPF中绑定的图片固定是6个,如果不够6个如何显示默认图?

    不够的部分使用占位图。

      imageList = new ObservableCollection<imageModel> {
                    new imageModel() { path= @"..\Images\placeholder.png" } ,
                     new imageModel() { path= @"..\Images\placeholder.png" } ,
                         new imageModel() { path= @"http://sipi.usc.edu/database/preview/misc/4.1.01.png" } ,
                             new imageModel() { path= @"http://sipi.usc.edu/database/preview/misc/4.1.02.png" } ,
                                 new imageModel() { path= @"http://sipi.usc.edu/database/preview/misc/4.1.03.png" } ,
                                     new imageModel() { path= @"http://sipi.usc.edu/database/preview/textures/1.1.12.png" } ,
    
                };
       <ListBox ItemsSource="{Binding imageList}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Height="120" Width="100">
                            <Image Source="{Binding path}"/>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>


    Sincerely,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 Lexan-Live 2017年12月19日 9:18
    2017年12月19日 8:49
    版主

全部回复

  • Hi,

    看起来你需要为每个image元素设置一个默认值,指向默认的占位图。

    Sincerely,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2017年12月19日 8:04
    版主
  • 有相关文章例子或demo吗?
    2017年12月19日 8:21
  • Hi,

    >> WPF中绑定的图片固定是6个,如果不够6个如何显示默认图?

    不够的部分使用占位图。

      imageList = new ObservableCollection<imageModel> {
                    new imageModel() { path= @"..\Images\placeholder.png" } ,
                     new imageModel() { path= @"..\Images\placeholder.png" } ,
                         new imageModel() { path= @"http://sipi.usc.edu/database/preview/misc/4.1.01.png" } ,
                             new imageModel() { path= @"http://sipi.usc.edu/database/preview/misc/4.1.02.png" } ,
                                 new imageModel() { path= @"http://sipi.usc.edu/database/preview/misc/4.1.03.png" } ,
                                     new imageModel() { path= @"http://sipi.usc.edu/database/preview/textures/1.1.12.png" } ,
    
                };
       <ListBox ItemsSource="{Binding imageList}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Height="120" Width="100">
                            <Image Source="{Binding path}"/>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>


    Sincerely,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 Lexan-Live 2017年12月19日 9:18
    2017年12月19日 8:49
    版主