• uwp 的】listView 选择


    xml 代码

    ----------------------------------------------------------

    <Page

        x:Class="ContentControlWithTemplateSelector.TestPage1"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:local="using:ContentControlWithTemplateSelector"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        mc:Ignorable="d">

        <Page.Resources>

            <DataTemplate x:Key="AvatarWithVisibility">

                <Grid >

                    <Grid Visibility="{Binding Converter={StaticResource RoomTypeConverter},ConverterParameter=Name}">

                        <Ellipse Fill="Green"></Ellipse>

                        <TextBlock Text="{Binding Index}" TextAlignment="Center" VerticalAlignment="Center"></TextBlock>

                    </Grid>

                    <Grid Visibility="{Binding Converter={StaticResource RoomTypeConverter},ConverterParameter=Image}">

                        <Ellipse >

                            <Ellipse.Fill>

                                <ImageBrush ImageSource="{Binding ImageUri}"></ImageBrush>

                            </Ellipse.Fill>

                        </Ellipse>

                    </Grid>

                    <Grid CacheMode="BitmapCache" Visibility="{Binding Converter={StaticResource RoomTypeConverter},ConverterParameter=Default}">

                        <Grid.RowDefinitions>

                            <RowDefinition></RowDefinition>

                            <RowDefinition Height="2*"></RowDefinition>

                            <RowDefinition></RowDefinition>

                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>

                            <ColumnDefinition></ColumnDefinition>

                            <ColumnDefinition Width="2*"></ColumnDefinition>

                            <ColumnDefinition></ColumnDefinition>

                        </Grid.ColumnDefinitions>

                        <Ellipse Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="2" Fill="Green">

                        </Ellipse>

                        <Ellipse Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Grid.ColumnSpan="2" Fill="Orange">

                        </Ellipse>

                    </Grid>

                </Grid>

            </DataTemplate>

        </Page.Resources>

        

        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

            <Grid.ColumnDefinitions>

                <ColumnDefinition></ColumnDefinition>

                <ColumnDefinition></ColumnDefinition>

            </Grid.ColumnDefinitions>

            <ListView x:Name="listViewAvatar" Grid.Column="0" ItemsSource="{Binding Rooms}">

                <ListView.ItemTemplate>

                    <DataTemplate>

                        <Grid>

                            <Grid.ColumnDefinitions>

                                <ColumnDefinition ></ColumnDefinition>

                                <ColumnDefinition></ColumnDefinition>

                            </Grid.ColumnDefinitions>

                            <ContentControl Grid.Column="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Width="50" Height="50"

                                            ContentTemplate="{StaticResource AvatarWithVisibility}"></ContentControl>

                            

                            <StackPanel Grid.Column="1" >

                                <TextBlock  Text="{Binding Name}"></TextBlock>

                                <TextBlock  Text="{Binding ImageUri}"></TextBlock>

                            </StackPanel>

                        </Grid>

                    </DataTemplate>

                </ListView.ItemTemplate>

            </ListView>

            <ContentControl Grid.Column="1" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"

                            Content="{Binding SelectedItem,ElementName=listViewAvatar}" Width="150" Height="150"

                            ContentTemplate="{StaticResource AvatarWithVisibility}"></ContentControl>

        </Grid>

    </Page>

    public sealed partial class TestPage1 : Page
    {
      public TestPage1()
      {
        this.InitializeComponent();
        this.DataContext = new DataViewModel();
      }
    }

    DataViewModel 代码

      public class DataViewModel

        {

            public ObservableCollection<Room> Rooms { get; set; }

            public DataViewModel()

            {

                Rooms = CreateRooms();

            }

            private ObservableCollection<Room> CreateRooms()

            {

                ObservableCollection<Room> rooms = new ObservableCollection<Room>();

                for (int i = 0; i < 10000; i++)

                {

                    var room = new Room { Index = i };

                    if (i % 3 == 0)

                    {

                        room.Name = "Room " + i;

                        if (i % 2 == 0)

                        {

                            room.ImageUri = new Uri( "ms-appx:///Assets/testImage.jpg");

                        }

                    }

                    rooms.Add(room);

                }

                return rooms;

            }

        }

  • 相关阅读:
    详述@Responsebody和HTTP异步请求的关系
    利用synchronized解析死锁的一种形成方式
    初识Spring JdbcTemplate
    初识SpringIOC
    JasperReport框架使用教程(附带常见空白页问题说明)
    LeetCode~1033.移动石子直到连续
    LeetCode~941.有效的山脉数组
    LeetCode~344. 反转字符串
    Job for network.service failed because the control process exited with error code问题
    LeetCode~报数(简单)
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14260252.html
Copyright © 2020-2023  润新知