首页 > 其他分享 >WPF集合绑定与数据模板

WPF集合绑定与数据模板

时间:2023-11-25 10:55:21浏览次数:31  
标签:set get 绑定 Header Add new WPF public 模板

普通List集合数据绑定

    public class DataSource
    {
        public string Name { get; set; } = "Hello";

        public ObservableCollection<string> list { get; set; } =
            new ObservableCollection<string>()
            {
                { "AAA"},
                { "BBB"},
                { "CCC"},
            };
    }
    <Window.DataContext>
        <local:DataSource/>
    </Window.DataContext>
    <StackPanel>
        <TextBlock Text="{Binding Name}"/>
        <ListBox ItemsSource="{Binding list}" Name="lb"/>
    </StackPanel>

设置子项的数据绑定模板

    public class DataSource
    {
        public string Name { get; set; } = "Hello";

        public ObservableCollection<DataItem> list { get; set; } =
            new ObservableCollection<DataItem>()
            {
                new DataItem{ id=1,Header="AAA",State=0},
                new DataItem{ id=2,Header="BBB",State=1},
                new DataItem{ id=3,Header="CCC",State=0},
            };
    }

    public class DataItem
    {
        public int id { get; set; }
        public string Header { get; set; }
        public int State { get; set; }
    }
    <Window.DataContext>
        <local:DataSource/>
    </Window.DataContext>
    <StackPanel>
        <TextBlock Text="{Binding Name}"/>
        <ListBox ItemsSource="{Binding list}" Name="lb">
            <!--子项模板-->
            <ListBox.ItemTemplate>
                <!--数据模板-->
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" TextBlock.Foreground="Gray" Name="sp">
                        <TextBlock Text="{Binding id}" Margin="10,0"/>
                        <TextBlock Text="{Binding Header}" Margin="10,0"/>
                        <TextBlock Text="{Binding DataContext.Name,RelativeSource={RelativeSource AncestorType=ListBox}}" Margin="10,0"/>
                        <TextBlock Text="{Binding DataContext.Name,ElementName=lb}" Margin="10,0"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </StackPanel>

数据模板触发器

    <!--<Window.DataContext>
        <local:DataSource/>
    </Window.DataContext>-->
    <StackPanel>
        <TextBlock Text="{Binding Name}"/>
        <ListBox ItemsSource="{Binding list}" Name="lb">
            <!--子项模板-->
            <ListBox.ItemTemplate>
                <!--数据模板-->
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" TextBlock.Foreground="Gray" Name="sp">
                        <TextBlock Text="{Binding id}" Margin="10,0"/>
                        <TextBlock Text="{Binding Header}" Margin="10,0"/>
                        <TextBlock Text="{Binding DataContext.Name,RelativeSource={RelativeSource AncestorType=ListBox}}" Margin="10,0"/>
                        <TextBlock Text="{Binding DataContext.Name,ElementName=lb}" Margin="10,0"/>
                        <TextBlock Text="{Binding State}"/>
                        <Button Content="处理" Name="btn" Visibility="Collapsed"/>
                    </StackPanel>
                    <DataTemplate.Triggers>
                        <!--<Trigger Property = "IsChecked" Value="True"> 判断的是对象的基本属性-->
                        <!--<DataTrigger 判断的是数据源中的数据属性-->
                        <!--数据模板选择器-->
                        <DataTrigger Binding="{Binding State}" Value="1">
                            <Setter TargetName="sp" Property="TextBlock.Foreground" Value="Red"/>
                            <Setter TargetName="btn" Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button Content="Button" Click="Button_Click"/>
    </StackPanel>

数据模板选择器

    public class MyDataTemplateSelector : DataTemplateSelector
    {
        public DataTemplate NoramlTemplate { get; set; }
        public DataTemplate WarningTemplate { get; set; }

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var di = item as DataItem;

            if (di.State == 1)
                return WarningTemplate;

            return NoramlTemplate;
        }
    }
    <Window.Resources>
        <DataTemplate x:Key="dt1">
            <StackPanel Orientation="Horizontal" TextBlock.Foreground="Gray" Name="sp">
                <TextBlock Text="{Binding id}" Margin="10,0"/>
                <TextBlock Text="{Binding Header}" Margin="10,0"/>
                <TextBlock Text="{Binding DataContext.Name,RelativeSource={RelativeSource AncestorType=ListBox}}" Margin="10,0"/>
                <TextBlock Text="{Binding DataContext.Name,ElementName=lb}" Margin="10,0"/>
                <TextBlock Text="{Binding State}"/>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="dt2">
            <StackPanel Orientation="Horizontal" TextBlock.Foreground="Red" Name="sp">
                <TextBlock Text="{Binding id}" Margin="10,0"/>
                <TextBlock Text="{Binding Header}" Margin="10,0"/>
                <TextBlock Text="{Binding DataContext.Name,RelativeSource={RelativeSource AncestorType=ListBox}}" Margin="10,0"/>
                <TextBlock Text="{Binding DataContext.Name,ElementName=lb}" Margin="10,0"/>
                <TextBlock Text="{Binding State}"/>
                <Button Content="处理" Name="btn"/>
            </StackPanel>
        </DataTemplate>

        <local:MyDataTemplateSelector x:Key="mdts"
                                      NoramlTemplate="{StaticResource dt1}"
                                      WarningTemplate="{StaticResource dt2}"/>
    </Window.Resources>

    <StackPanel>
        <TextBlock Text="{Binding Name}"/>
        <ListBox ItemsSource="{Binding list}" Name="lb">
            <!--子项模板-->
            <ListBox.ItemTemplate>
                <!--数据模板-->
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" TextBlock.Foreground="Gray" Name="sp">
                        <TextBlock Text="{Binding id}" Margin="10,0"/>
                        <TextBlock Text="{Binding Header}" Margin="10,0"/>
                        <TextBlock Text="{Binding DataContext.Name,RelativeSource={RelativeSource AncestorType=ListBox}}" Margin="10,0"/>
                        <TextBlock Text="{Binding DataContext.Name,ElementName=lb}" Margin="10,0"/>
                        <TextBlock Text="{Binding State}"/>
                        <Button Content="处理" Name="btn" Visibility="Collapsed"/>
                    </StackPanel>
                    <DataTemplate.Triggers>
                        <!--<Trigger Property = "IsChecked" Value="True"> 判断的是对象的基本属性-->
                        <!--<DataTrigger 判断的是数据源中的数据属性-->
                        <!--数据模板选择器-->
                        <DataTrigger Binding="{Binding State}" Value="1">
                            <Setter TargetName="sp" Property="TextBlock.Foreground" Value="Red"/>
                            <Setter TargetName="btn" Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button Content="Button" Click="Button_Click"/>

        <ListBox ItemsSource="{Binding list}">
            <ListBox.ItemTemplateSelector>
                <local:MyDataTemplateSelector 
                    WarningTemplate="{StaticResource dt2}" 
                    NoramlTemplate="{StaticResource dt1}"/>
            </ListBox.ItemTemplateSelector>
        </ListBox>

        <ListBox ItemsSource="{Binding list}" ItemTemplateSelector="{StaticResource mdts}"/>
    </StackPanel>

将模板实例传到MyDataTemplateSelector,设置ListBox的ItemTemplateSelector属性引用MyDataTemplateSelector,自动判断使用哪种模板。

ListView、DataGrid、TreeView

    public class DataSource
    {
        // 静态属性

        public string Name { get; set; } = "Hello";


        public object CurrentItem { get; set; }
        public int CurrentId { get; set; }

        public ObservableCollection<DataItem> list { get; set; } =
            new ObservableCollection<DataItem>()
            {
                new DataItem{ id=1,Header="AAA",State=0},
                new DataItem{ id=2,Header="BBB",State=1},
                new DataItem{ id=3,Header="CCC",State=0},
            };


        public DataSource()
        {
            list[0].Children.Add(new DataItem { Header = "AAA-1"});
            list[0].Children.Add(new DataItem { Header = "AAA-2"});

            list[1].Children.Add(new DataItem { Header = "BBB-1" });
            list[1].Children.Add(new DataItem { Header = "BBB-2" });

            list[2].Children.Add(new DataItem { Header = "CCC-1" });
            list[2].Children.Add(new DataItem { Header = "CCC-2" });


            list[0].Children[0].Children.Add(new DataItem { Header = "AAA-1-1" });
        }


    }

    public class DataItem
    {
        public string Icon { get; set; }
        public int id { get; set; }
        public string Header { get; set; }
        public int State { get; set; }

        public List<DataItem> Children { get; set; } = new List<DataItem>();

        // 自己嵌套自己  无限层级
    }
    <Window.DataContext>
        <local:DataSource/>
    </Window.DataContext>
    <StackPanel>
        <!--第二类-->
        <ListView ItemsSource="{Binding list}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="ID" DisplayMemberBinding="{Binding id}"/>
                    <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Header}"/>
                </GridView>
            </ListView.View>
        </ListView>
        <DataGrid ItemsSource="{Binding list}" AutoGenerateColumns="False" CanUserAddRows="False">
            <DataGrid.Columns>
                <DataGridTextColumn Header="编号" Binding="{Binding id}"/>
                <DataGridTextColumn Header="名称" Binding="{Binding Header}"/>
            </DataGrid.Columns>
        </DataGrid>

        <!--第三类-->
        <TreeView ItemsSource="{Binding list}">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="@"/>
                        <TextBlock Text="{Binding Header}" Grid.Column="1"/>
                    </Grid>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
    </StackPanel>

ItemsControl、ListBox

    /// <summary>
    /// ColumnChartWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ColumnChartWindow : Window
    {
        ChartDataSource cds = new ChartDataSource();
        public ColumnChartWindow()
        {
            InitializeComponent();

            this.DataContext = cds;
        }
        ~ColumnChartWindow()
        {
            cds.Dispose();
        }
    }
    public class ChartDataSource
    {
        public ObservableCollection<ColumnItem> datas { get; set; } =
            new ObservableCollection<ColumnItem>();
        CancellationTokenSource cts = new CancellationTokenSource();
        Task task;
        public ChartDataSource()
        {
            for (int i = 0; i < 15; i++)
            {
                datas.Add(new ColumnItem
                {
                    Value = new Random().Next(10, 200),
                    LabelText = DateTime.Now.ToString("mm:ss")
                });
            }
            task = Task.Run(async () =>
            {
                while (!cts.IsCancellationRequested)
                {
                    await Task.Delay(1000);
                    // 出错
                    try
                    {
                        //ObservableCollection这个类型的数据,会导致界面的对象渲染变更(控件的增减)
                        // 界面上的操作都需要在UI线程(主线程)处理
                        // Task属于子线程(后台线程,不是主线程)

                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            datas.Add(new ColumnItem()
                            {
                                Value = new Random().Next(10, 200),
                                LabelText = DateTime.Now.ToString("mm:ss")
                            });

                            if (datas.Count > 20)
                                datas.RemoveAt(0);
                        });
                    }
                    catch (Exception ex)
                    {

                    }
                }
            }, cts.Token);
        }
        ~ChartDataSource()
        {

        }
        public void Dispose()
        {
            // 销毁线程

            cts.Cancel();
            task.Wait(5000);
        }
    }
    public class ColumnItem
    {
        public string LabelText { get; set; }
        public int Value { get; set; }
    }
<Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <ItemsControl ItemsSource="{Binding datas}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>
                        <Border Height="1" Background="Gray" VerticalAlignment="Bottom"/>
                        <Border Width="12" Height="{Binding Value}" Background="Orange" VerticalAlignment="Bottom" Margin="0,0,0,1"/>
                        <TextBlock Text="{Binding LabelText}" Grid.Row="1" Margin="5,0"/>
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

        <ListBox ItemsSource="{Binding datas}" Grid.Row="1">
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <!--<Setter Property="VerticalContentAlignment" Value="Bottom"/>-->
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <Border Background="{TemplateBinding Background}">
                                    <ContentPresenter/>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" Value="Gray"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>
                        <Border Height="1" Background="Gray" VerticalAlignment="Bottom"/>
                        <Border Width="12" Height="{Binding Value}" Background="Orange" VerticalAlignment="Bottom" Margin="0,0,0,1"/>
                        <TextBlock Text="{Binding LabelText}" Grid.Row="1" Margin="5,0"/>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>

        </ListBox>
    </Grid>

ComboBox

    public class MultiLevelDataSource : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler? PropertyChanged;
        // 列表中的子项数据:id\Header\ParentId
        public List<Area> AreaAll { get; set; } = new List<Area>();
        public int CurrentCIndex { get; set; } = 0;
        public int CurrentDIndex { get; set; } = 0;

        private int _currentPCode;
        public int CurrentPCode
        {
            get => _currentPCode;
            set
            {
                _currentPCode = value;
                var cs = AreaAll.Where(a => a.ParentCode == value).ToList();
                CityList.Clear();
                foreach (var item in cs)
                {
                    CityList.Add(item);
                }
                var ds = AreaAll.Where(a => a.ParentCode == CityList[0].Code).ToList();
                DistrictList.Clear();
                foreach (var item in ds)
                {
                    DistrictList.Add(item);
                }
                //CurrentCIndex = 0;
                //CurrentDIndex = 0;
                //PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentCIndex"));
                //PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentDIndex"));
            }
        }
        private int _currentCity;
        public int CurrentCCode
        {
            get => _currentCity;
            set
            {
                _currentCity = value;
                var ds = AreaAll.Where(a => a.ParentCode == value).ToList();
                DistrictList.Clear();
                foreach (var item in ds)
                {
                    DistrictList.Add(item);
                }
                //CurrentDIndex = 0;
                //PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentDIndex"));
            }
        }
        public int CurrentDCode { get; set; }
        public ObservableCollection<Area> ProvinceList { get; set; }
        public ObservableCollection<Area> CityList { get; set; }
        public ObservableCollection<Area> DistrictList { get; set; }
        public MultiLevelDataSource()
        {
            ProvinceList = new ObservableCollection<Area>();
            CityList = new ObservableCollection<Area>();
            DistrictList = new ObservableCollection<Area>();
            Task.Run(async () =>
            {
                await Task.Delay(1000); // 耗时操作
                // 获取到数据后,进行页面初始化
                AreaAll.Add(new Area { Code = 1, Header = "湖北", ParentCode = 0 });
                AreaAll.Add(new Area { Code = 2, Header = "江苏", ParentCode = 0 });
                AreaAll.Add(new Area { Code = 3, Header = "武汉", ParentCode = 1 });
                AreaAll.Add(new Area { Code = 4, Header = "襄阳", ParentCode = 1 });
                AreaAll.Add(new Area { Code = 5, Header = "南京", ParentCode = 2 });
                AreaAll.Add(new Area { Code = 6, Header = "苏州", ParentCode = 2 });
                AreaAll.Add(new Area { Code = 7, Header = "武昌", ParentCode = 3 });
                AreaAll.Add(new Area { Code = 8, Header = "洪山", ParentCode = 3 });
                AreaAll.Add(new Area { Code = 9, Header = "江岸", ParentCode = 3 });
                AreaAll.Add(new Area { Code = 10, Header = "襄城", ParentCode = 4 });
                AreaAll.Add(new Area { Code = 11, Header = "樊成", ParentCode = 4 });
                AreaAll.Add(new Area { Code = 12, Header = "襄州", ParentCode = 4 });
                AreaAll.Add(new Area { Code = 13, Header = "玄武", ParentCode = 5 });
                AreaAll.Add(new Area { Code = 14, Header = "建邺", ParentCode = 5 });
                AreaAll.Add(new Area { Code = 15, Header = "鼓楼", ParentCode = 5 });
                AreaAll.Add(new Area { Code = 16, Header = "姑苏", ParentCode = 6 });
                AreaAll.Add(new Area { Code = 17, Header = "相城", ParentCode = 6 });
                AreaAll.Add(new Area { Code = 18, Header = "吴中", ParentCode = 6 });

                Application.Current.Dispatcher.Invoke(() =>
                {
                    var ps = AreaAll.Where(a => a.ParentCode == 0).ToList();
                    foreach (var item in ps)
                    {
                        ProvinceList.Add(item);
                    }
                    //var cs = AreaAll.Where(a => a.ParentCode == ProvinceList[0].Code).ToList();
                    //foreach (var item in cs)
                    //{
                    //    CityList.Add(item);
                    //}
                    //var ds = AreaAll.Where(a => a.ParentCode == CityList[0].Code).ToList();
                    //foreach (var item in ds)
                    //{
                    //    DistrictList.Add(item);
                    //}
                    CurrentPCode = 2; CurrentCCode = 5; CurrentDCode = 13;
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentPCode"));
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentCCode"));
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentDCode"));
                });
                //CurrentCIndex = 0;
                //CurrentDIndex = 0;
                //PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentCIndex"));
                //PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CurrentDIndex"));
            });
        }
    }
    public class Area
    {
        public int Code { get; set; }
        public string Header { get; set; }
        public int ParentCode { get; set; }
    }
    <Window.DataContext>
        <local:DataSource/>
    </Window.DataContext>
    <StackPanel>
        <ComboBox Width="200" Height="45" VerticalAlignment="Top"
                  ItemsSource="{Binding list}" SelectedIndex="0"
                  DisplayMemberPath="Header"
                  SelectedValuePath="id"
                  SelectedValue="{Binding CurrentId}"
                  SelectedItem="{Binding CurrentItem}">
        </ComboBox>
        <!--DisplayMemberPath="Header"   这种设置因为数据源是复杂类型  List<string>-->
        <!--SelectedItem  对应的是ComboBoxItem的子项-->
        <ComboBox Width="200" Height="45" VerticalAlignment="Top"
                  SelectedIndex="0"               
                  
                  SelectedItem="{Binding CurrentItem}">
            <ComboBoxItem>
                <TextBlock Text="AAA"/>
            </ComboBoxItem>
            <ComboBoxItem>
                <TextBlock Text="BBB"/>
            </ComboBoxItem>
        </ComboBox>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
            <StackPanel.DataContext>
                <local:MultiLevelDataSource/>
            </StackPanel.DataContext>
            <ComboBox Width="200" Height="45" ItemsSource="{Binding ProvinceList}"
                      SelectedIndex="0"
                      DisplayMemberPath="Header"
                      SelectedValuePath="Code"
                      SelectedValue="{Binding CurrentPCode}"/>
            <ComboBox Width="200" Height="45" ItemsSource="{Binding CityList}"
                      SelectedIndex="{Binding CurrentCIndex}"
                      DisplayMemberPath="Header"
                      SelectedValuePath="Code"
                      SelectedValue="{Binding CurrentCCode}"/>
            <ComboBox Width="200" Height="45" ItemsSource="{Binding DistrictList}"
                      SelectedIndex="{Binding CurrentDIndex}"
                      DisplayMemberPath="Header"
                      SelectedValuePath="Code"
                      SelectedValue="{Binding CurrentDCode}"/>
        </StackPanel>
    </StackPanel>

标签:set,get,绑定,Header,Add,new,WPF,public,模板
From: https://www.cnblogs.com/ZHIZRL/p/17854306.html

相关文章

  • Go语言开源跨平台GUI框架Fyne小教程|数据绑定篇
    入门数据绑定是在Fyne工具包v2.0.0版本中引入的的一个强大功能。通过使用数据绑定,我们可以避免手动管理许多标准对象,如标签、按钮和列表等,的数据内容。Fyne内置绑定支持许多基本数据类型(如Int、String、Float等),还有列表(如StringList、BoolList)以及Map和Struct绑定。这些类型中的每......
  • 【C++ Primer Plus】类、运算符重载、虚函数、友元函数模板
    1.运算符重载1.1普通运算符重载在类内重写operator+函数,实现加号运算符的重载,下面给出了两种调用方式,注意加号前为调用者,加号后为参数,第三行代码的完整写法实际上是第四行TimeTime::operator+(intminutes)const;Timetime;Timetime2=time+50;Timetime3=time.o......
  • pyinstaller利用spec文件打包的使用模板
    pyinstaller打包使用pyqt5开发软件,当项目越来越大,引用的资源越来越多时,那么使用pyinstaller进行打包,如果不利用spec文件,是很难满足打包需求的。spec文件,其实你在使用pyinstallermain.py打包时,也是会自动生成的,叫main.spec。不过,如果你想把自己的资源文件一起打进包去,则需......
  • P3371 【模板】单源最短路径
    【模板】单源最短路径(标准版)题目背景2018年7月19日,某位同学在NOIDay1T1归程一题里非常熟练地使用了一个广为人知的算法求最短路。然后呢?\(100\rightarrow60\);\(\text{Ag}\rightarrow\text{Cu}\);最终,他因此没能与理想的大学达成契约。小F衷心祝愿大家不再......
  • Excel导入sql语句模板,解决转换时间戳问题
    EXCEL导入MySQL生成sql语句解决时间戳问题生成普通sql语句解决时间戳问题这里使用’"&TEXT(E1,“yyyy-mm-ddhh:mm:ss”)&"’解决excel表中时间戳问题的生成使用str_to_date(’"&TEXT(E1,“yyyy-mm-ddhh:mm:ss”)&"’,’%Y-%m-%d%T’))解决插入mysql中的问题="insertintoxx......
  • cad模板
    1、制作一个cad模板保存为块2、打开设计中心3、找到模板位置——右键创建选项面板 4、打开工具选项面板  5、直接点击模板后点击制图空间空白处即可使用 ......
  • WPF数据绑定
    依赖对象做为数据源如果绑定的源是依赖对象的依赖属性,那么这个依赖属性发生实时变化的时候,会同步到绑定目标。如果绑定的源是非依赖属性,那么这个属性发生变化的的时候,不会同步到绑定目标。被绑定的数据源,需要是属性。<StackPanel><!--目标对象:TextBlock-->......
  • Service 服务详解 及自定义服务模板
    文章目录1、服务简介2、服务的生命周期1)Service的启动停止2)、服务的生命周期的方法3、使用startService启动后服务的生命周期1)、文件结构2)activity_main.xml文件3)、myService自定义服务文件4)、MainActivity文件5)、AndroidManifest.xml文件6)、打印的相关log5、使用bindS......
  • interface 接口回调简单模板
    文章目录1、功能简介2、MainActivity文件3、Message文件4、log打印1、功能简介方便在不同类,不同activity之间进行数据传递文件结构:Mainactvity向Message里面传数据,Message处理后,通过接口将处理过后的数据返回到MainActivity2、MainActivity文件packagecom.example.ubun......
  • recycleView 简单模板框架
    文章目录1、功能简介2、文件结构3、build.gradle(Module:app)4、activity_main.xml文件5、recycleview_item.xml6、RecycleViewAdapter文件7、StudentData文件8、MainActivity文件1、功能简介实现recycle和自定义item的适配读取姓名2、文件结构3、build.gradle(Module:......