WPF 做卡片列表

页面效果
在这里插入图片描述
代码

<Window x:Class="WpfApp2.ListBox"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp2"
        mc:Ignorable="d"
        Title="ListBox" Height="450" Width="800" Loaded="ListBox_OnLoaded">
    <Window.Resources>
        <!--GridView Header样式 去除Gridview自带的Header框-->
        <Style TargetType="{x:Type GridViewColumnHeader}" >
            <!--<Setter Property="HorizontalContentAlignment" Value="Center"/>-->
            <Setter Property="Visibility" Value="Hidden"/>
            <Setter Property="Height" Value="0"></Setter>
        </Style>
        <!--ListView 布局样式 使图片可以横向展示-->
        <Style  TargetType="{x:Type ListView}" >
            <Setter Property='ItemsPanel'>
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <WrapPanel  Width="{Binding (FrameworkElement.ActualWidth), RelativeSource={RelativeSource   AncestorType=ScrollContentPresenter}}"></WrapPanel>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!--ListView Item样式和点击后样式模板-->
        <ControlTemplate x:Key="ListViewItemTemplate" TargetType="ListBoxItem">
            <Border Name="Border">
                <StackPanel>
                    <GridViewRowPresenter>
                    </GridViewRowPresenter>
                </StackPanel>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsSelected" Value="true">
                    <Setter TargetName="Border"  Property="Background" Value="#ffff"/>
                </Trigger>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="Border"  Property="Background" Value="#ffff00"/>
                </Trigger>
                <Trigger Property="IsFocused" Value="True">
                    <Setter TargetName="Border" Property="Background" Value="Green"></Setter>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
        <!--ListView Item样式和点击后样式-->
        <Style TargetType="ListViewItem">
            <Setter Property="Template" Value="{StaticResource ListViewItemTemplate}"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter>
        </Style>

    </Window.Resources>
    <Grid>
        <!-- ListView 中的ScrollViewer.HorizontalScrollBarVisibility="Disabled" 代码的意思是为了让WrapPanel 可以自带换行-->
        <ListView Name="lbList" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
            <ListView.View>
                <GridView >
                    <GridView.Columns>
                        <GridViewColumn >
                            <GridViewColumnHeader></GridViewColumnHeader>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel Margin="10 20 0 0" >
                                        <Border Width="112" Height="167" Name="Bor_Movie1" >
                                            <Border.Background>
                                                <ImageBrush ImageSource="https://timgsa.baidu.com/timg?image&amp;quality=80&amp;size=b9999_10000&amp;sec=1601785919991&amp;di=5aa5504ee4337c2f857951b6759a5072&amp;imgtype=0&amp;src=http%3A%2F%2Ft7.baidu.com%2Fit%2Fu%3D3616242789%2C1098670747%26fm%3D79%26app%3D86%26f%3DJPEG%3Fw%3D900%26h%3D1350"></ImageBrush>
                                            </Border.Background>
                                        </Border>
                                        <Label MaxWidth="112"  Margin="0,10,0,0" >
                                            <TextBlock TextWrapping="Wrap" TextAlignment="Center" FontSize="12" FontWeight="Bold" Text="{Binding Name}" Height="27" Width="105"></TextBlock>
                                        </Label>
                                    </StackPanel>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView.Columns>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</Window>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
WPF 中获取 Mac 地址列表,可以使用 System.Net.NetworkInformation 命名空间中的 NetworkInterface 类来实现。 首先,需要添加对 System.Net.NetworkInformation 命名空间的引用。 然后,可以通过 NetworkInterface 类的 GetAllNetworkInterfaces 方法获取所有网络接口的信息,包括每个接口的 Mac 地址。 以下是一个示例代码: ``` using System.Net.NetworkInformation; List<string> macList = new List<string>(); foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) { if (nic.OperationalStatus == OperationalStatus.Up) { PhysicalAddress address = nic.GetPhysicalAddress(); byte[] bytes = address.GetAddressBytes(); string macAddress = string.Empty; for (int i = 0; i < bytes.Length; i++) { macAddress += string.Format("{0}{1}", bytes[i].ToString("X2"), (i != bytes.Length - 1) ? "-" : ""); } macList.Add(macAddress); } } // macList 中存储了获取到的 Mac 地址列表 ``` 上述代码首先创建了一个字符串列表 macList,用来存储获取到的 Mac 地址。 然后使用 foreach 循环遍历 GetAllNetworkInterfaces 方法返回的所有网络接口。 对于每个网络接口,通过判断 OperationalStatus 属性是否为 Up,可以确定该接口是否处于可用状态。 如果接口状态为 Up,则通过 GetPhysicalAddress 方法获取该网络接口的物理地址。 接着,获取到的物理地址是一个 byte 数组,我们需要将其转换为十六进制的字符串表示。遍历 byte 数组,使用 string.Format 方法将每个字节转换为十六进制,并将字节之间用 "-" 连接起来,得到完整的 Mac 地址字符串。 最后,将获取到的 Mac 地址字符串添加到 macList 列表中。 通过以上代码,我们可以获取到系统上所有可用网络接口的 Mac 地址列表

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值