首页 > 其他分享 >WPF 设置圆角窗体,通过ListView模拟下拉组合款

WPF 设置圆角窗体,通过ListView模拟下拉组合款

时间:2023-05-27 15:34:46浏览次数:42  
标签:sender void object private 窗体 Visibility WPF ListView

界面:

<Window x:Class="WpfApp2.MainWindow"
        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" WindowStyle="None"  OpacityMask="White" AllowsTransparency="True" ResizeMode="NoResize" MouseDown="Window_MouseDown"  
        Title="MainWindow" Height="650" Width="530"  WindowStartupLocation="CenterOwner"  Background="Transparent">
    <Window.Resources>
        <!--<Style TargetType="Window" x:Key="RoundedCornerWindowStyle">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Window">
                        <Border  Background="White" CornerRadius="15" Opacity="0.8">
                            <ContentPresenter/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>-->

        <Style TargetType="Image" x:Key="Image_Style">
            <Setter Property="Width" Value="50"></Setter>
            <Setter Property="Height" Value="50"></Setter>
            <Setter Property="Clip">
                <Setter.Value>
                    <EllipseGeometry RadiusX="25" RadiusY="25" Center="25,25"/>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="Border" x:Key="Border_Style">
            <Setter Property="Width" Value="385"></Setter>
            <Setter Property="BorderBrush" Value="Gray"></Setter>
            <Setter Property="CornerRadius" Value="10"></Setter>
            <Setter Property="BorderThickness" Value="0.5"></Setter>
            <Setter Property="Margin" Value="10"></Setter>
        </Style>
        <Style TargetType="TextBlock" x:Key="TextBlock_Base_Style">
            <Setter Property="FontSize" Value="18"></Setter>
        </Style>
        <Style x:Key="Title_Style" TargetType="TextBlock" BasedOn="{StaticResource ResourceKey=TextBlock_Base_Style}" >
            <Setter Property="FontWeight" Value="Bold"></Setter>
            <Setter Property="Foreground" Value="#232b6e"></Setter>
        </Style>
        <Style x:Key="Text_Style" TargetType="TextBlock" BasedOn="{StaticResource ResourceKey=TextBlock_Base_Style}" >

            <Setter Property="Foreground" Value="#6269a5"></Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid Background="Transparent">
            <Border BorderThickness="5" BorderBrush="White" CornerRadius="10,10,10,10"  Name="top">
                <Border.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="White"/>
                    </LinearGradientBrush>
                </Border.Background>
            </Border>
        </Grid>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <!--<TextBlock x:Name="EntListWelcome1" Text="< 返回" HorizontalAlignment="Left" FontSize="15" Height="34"  />
                <TextBlock x:Name="EntListWelcome" Text="EntListWelcome" HorizontalAlignment="Left" FontSize="15" Height="34" Width="345" FontWeight="Bold"/>
                <TextBlock x:Name="EntListIntroduce" Text="EntListIntroduce" HorizontalAlignment="Left" Margin="0,-42,0,0" VerticalAlignment="Top" Width="400"/>-->

            </Grid>
            <Border Style="{StaticResource ResourceKey=Border_Style}"   Grid.Row="1"  >
                <StackPanel>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                    </Grid>
                    <Grid Grid.Row="0" Height="85" Background="Transparent">
                        <Image HorizontalAlignment="Left" Margin="20 0 0 0" VerticalAlignment="Center" Style="{StaticResource ResourceKey=Image_Style}"  Source="/model_.png"   />
                        <TextBlock  Style="{StaticResource ResourceKey=Title_Style}"      HorizontalAlignment="Left" Margin="100 0 0 0" VerticalAlignment="Center" Text="标题1" Width="50"  />
                        <TextBlock x:Name="ShowEnterpriseAccount"  Margin="0 0 15 0"  MouseLeftButtonDown="ShowEnterpriseAccount_MouseDown" HorizontalAlignment="Right" VerticalAlignment="Center" Text=">" FontSize="20"/>
                        <TextBlock x:Name="HideEnterpriseAccount" Visibility="Collapsed" MouseLeftButtonDown="HideEnterpriseAccount_MouseLeftButtonDown"  HorizontalAlignment="Right" VerticalAlignment="Center" Text="∨" Margin="0 0 10 0" FontSize="20"/>
                    </Grid>
                    <Grid  Grid.Row="1" Background="Transparent">
                        <ListView x:Name="EnterpriseAccount_ListView" Margin="25 0 0 10"   Visibility="Visible" Width="340"   Height="200"  BorderThickness="0"   >
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <Grid Height="60">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="200"/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <!--<Image Source="{Binding ImageUrl}" Width="50" Height="50" Margin="5"/>-->
                                        <Image Style="{StaticResource ResourceKey=Image_Style}"  Width="50" Height="50" Source="{Binding ImageUrl}" >
                                        </Image>
                                        <TextBlock Margin="20 0 0 0" Grid.Column="1" Text="{Binding Name}"  Style="{StaticResource ResourceKey=Title_Style}"  />
                                        <TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="20 25 0 0"  Style="{StaticResource ResourceKey=Text_Style}"   Text="{Binding Name}"    />
                                        <TextBlock Grid.Column="2" VerticalAlignment="Center" Foreground="#484e86" Text=">" FontSize="20"/>
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </Grid>
                </StackPanel>
            </Border>
            <Border Style="{StaticResource ResourceKey=Border_Style}"  Grid.Row="2">
                <StackPanel>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                    </Grid>
                    <Grid Grid.Row="0" Height="85" Background="Transparent">
                        <Image HorizontalAlignment="Left" Margin="20 0 0 0" VerticalAlignment="Center" Style="{StaticResource ResourceKey=Image_Style}"  Source="/model_.png"   />
                        <TextBlock  HorizontalAlignment="Left" Margin="100 0 0 0" VerticalAlignment="Center" Text="标题2" Width="50"  Style="{StaticResource ResourceKey=Title_Style}"    />
                        <TextBlock x:Name="ShowPersonAccount" Foreground="#484e86"   Margin="0 0 15 0"  MouseLeftButtonDown="ShowPersonAccount_MouseLeftButtonDown" HorizontalAlignment="Right" VerticalAlignment="Center" Text=">" FontSize="20"/>
                        <TextBlock x:Name="HidePersonAccount" Visibility="Collapsed" MouseLeftButtonDown="HidePersonAccount_MouseLeftButtonDown"  HorizontalAlignment="Right" VerticalAlignment="Center" Text="∨" Foreground="#484e86"  Margin="0 0 10 0" FontSize="20"/>
                    </Grid>
                    <Grid  Grid.Row="1" Background="Transparent">
                        <ListView x:Name="list_view_person" Margin="25 0 0 10"   Visibility="Visible" Width="340"   Height="200"  BorderThickness="0"   d:ItemsSource="{d:SampleData ItemCount=3}">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <Grid Height="60">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="200"/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <!--<Image Source="{Binding ImageUrl}" Width="50" Height="50" Margin="5"/>-->
                                        <Image Style="{StaticResource ResourceKey=Image_Style}"  Width="50" Height="50" Source="/model_.png" >
                                        </Image>
                                        <TextBlock Margin="20 0 0 0" Grid.Column="1" Text="标题1_deteail" Style="{StaticResource ResourceKey=Title_Style}"  />
                                        <TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="20 25 0 0"  Style="{StaticResource ResourceKey=Text_Style}" Text="测试客户"  />
                                        <TextBlock Grid.Column="2" VerticalAlignment="Center" Text=">"  Foreground="#484e86"  FontSize="20"/>
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </Grid>
                </StackPanel>
            </Border>
        </Grid>
    </Grid>
</Window>

后台:

   /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            EnterpriseAccount_ListView.ItemsSource = new List<EtpListInfoJson> { new EtpListInfoJson() {
                ImageUrl= "https://bkimg.cdn.bcebos.com/
pic/a6efce1b9d16fdfaaf51d41cfbda9b5494eef11fcdbe?x-bce-process=image/resize,m_lfit,w_536,limit_1", Name = "12", }, new EtpListInfoJson() { ImageUrl= "pack://application:,,,/WpfApp2;Component/11.png", Name = "ss", }, new EtpListInfoJson() { ImageUrl= "pack://application:,,,/WpfApp2;Component/11.png", Name = "ss21", }, new EtpListInfoJson() { ImageUrl= "pack://application:,,,/WpfApp2;Component/11.png", Name = "fd", }, }; } private void Button_Click(object sender, RoutedEventArgs e) { EnterpriseAccount_ListView.Visibility = Visibility.Visible; } private void Grid_MouseDown(object sender, MouseButtonEventArgs e) { EnterpriseAccount_ListView.Visibility = Visibility.Visible; } private void ShowEnterpriseAccount_MouseDown(object sender, MouseButtonEventArgs e) { HideEnterpriseAccount.Visibility = Visibility.Visible; ShowEnterpriseAccount.Visibility = Visibility.Collapsed; EnterpriseAccount_ListView.Visibility = Visibility.Visible; } private void HideEnterpriseAccount_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { ShowEnterpriseAccount.Visibility = Visibility.Visible; HideEnterpriseAccount.Visibility = Visibility.Collapsed; EnterpriseAccount_ListView.Visibility = Visibility.Collapsed; } private void ShowPersonAccount_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { } private void HidePersonAccount_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { } private void Window_MouseDown(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DragMove(); } } }

效果:

 

标签:sender,void,object,private,窗体,Visibility,WPF,ListView
From: https://www.cnblogs.com/anjingdian/p/17436804.html

相关文章

  • WPF入门实例 WPF完整例子 WPF DEMO WPF学习完整例子 WPF实战例子 WPF sql实例应用 WPF
    WPF和WinForms都是用于创建Windows桌面应用程序的开发框架,它们有一些相似之处,但也有很多不同之处。在开发速度方面,这取决于具体情况。如果您熟悉WinForms开发并且正在开发简单的界面应用程序,则可能会比使用WPF更快速地完成任务。然而,在设计和实现复杂的用户界面时,WPF可......
  • Wpf基础入门——容器Panel篇
    WPF布局基础WPF的布局原则一个窗口中只能包含一个元素不应显示设置元素尺寸不应使用坐标设置元素的位置可以嵌套布局容器WPF有哪些布局容器?Grid:网格。可以自定义行和列并通过行列的数量、行高和列宽来调整控件的布局。近似于HTML中的Table。StackPanel:栈式面板。可将......
  • WPF三层架构的搭建
    小编首先来给大家介绍一下,什么是三层架构:三层架构就是为了符合“高内聚,低耦合”思想,把各个功能模块划分为表示层(UI)、业务逻辑层(BLL)和数据访问层(DAL)三层架构,各层之间采用接口相互访问,并通过对象模型的实体类(Model)作为数据传递的载体,不同的对象模型的实体类一般对应于数据库的不同表,......
  • 【盘点】界面控件DevExpress WPF的几大应用程序主题
    DevExpressWPF控件包含了50+个应用程序主题和40个调色板,用户可以在发布应用程序是指定主题,或允许最终用户动态修改WPF应用程序的外观和样式,其中主题带有调色板,可以进一步个性化您的UI!PS:DevExpressWPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。......
  • WPF 使用Background="Transparent"+AllowsTransparency="True"实现穿透效果,窗体多次渲
    如果在WPF中的窗体使用AllowsTransparency="True"实现穿透效果,那么该窗体如果移动、快速渲染、控件比较多的情况,会出现卡顿,CPU暴涨的问题。基于以上情况,可以使用另一种方式实现,由@wuty@terryK指导:usingSystem.Windows;usingAnnotation.Business;namespaceDemo{//......
  • pb中打开窗体时用户权限检查以及控制工具栏按钮的显示状态
    说明:首先在菜单栏方法中修改对应的name和tag(否则程序无法判断统一判为没权限) im_main=this.MenuID//整体控制工具栏按钮隐藏im_main.of_Set({'m_open','m_printpreview','m_print','m_saveas'},'visible',false)//根据用户权限设置工具栏按钮的显示状态im_mai......
  • WPF实现两个DataGrid列表的滚动条同步
    实现目标:左右两个DataGrid对比显示,希望拖动一个列表的滚动条,就把别一个列表的滚动条移动到相应位置。 主要思路是:通过FindVisualChildren找到两个DataGrid的ScrollViewer控件,然后注册两个控件的ScrollChanged事件,只要有一个ScrollViewer的VerticalOffset值变了,就相应地修改另......
  • xiaofeng.NET系列之 netcore c#快速导出数据CSV格式 winfrom wpf
    一个导出buttonnuget搜索 usingXiaoFeng.IO;usingXiaoFeng; privatevoidbutton1_Click(objectsender,EventArgse){varsavedlg=newFolderBrowserDialog(){Description="选择保存的路径",......
  • Java的GUI窗体出现中文不能正确显示解决方法
    问题描述:用java做一个图形化界面的程序,在Eclipse上运行后中文显示方框,如下图所示:解决方法:在要运行的代码上右键RunAs-->RunConfigurations...在Arguments-->VMarguments:中增加下面这句:-Dfile.encoding=gbk点击Apply,然后运行  成功显示中文......
  • WPF 依赖属性
    一、简介在WPF中,最常见属性就是依赖属性,支持数据绑定的属性都是依赖属性,像Button的Content就是一个依赖属性DependencyProperty。依赖属性没有值,可以依赖绑定源来获取值换句话说,只有依赖属性支持数据绑定,当我们需要一些特殊的属性而该控件没有时,就可以为其添加一个依赖......