建一个百度地图
var map=new BMap.Map(“divid”);
地图初始化需要调用以下方法(设置中心点(lng,lat),以缩放级别(scaledLevel));
map.centerAndZoom(new BMap.Point(lng,lat),scaledLevel);
对于只加载一个地图的页面,这样就OK了,不会产生如题描述的问题;那么问题来了,比如:我要编辑一个地方,用AJAX load的一个页面,里面有地图而且我完成操作只关闭弹出窗口并不刷新页面时,这时如何新建地图是各种问题。
解决方法:只有一条需要谨记,百度地图初始化之后就再不能被隐藏,如果隐藏之后再显示并且你想地图显示之后设置新的中心点,新的点地图永远不置中无论你调用map.setCenter(point) or panTo(point)方法; 那么方法来了,可以把地图挪到一个宽为0或者高为0的div节点中并设置overflow:hidden,地图仍然在显示但是用户并不可见,再显示地图置中就没有问题。
附加一点:如果使用map.getContainer()获取map HTMLElemet ,那么在下一次把它append到Dom中,应在之前完成初始化的动作!
读导航
本文介绍使用第三方开源库 Dragablz 实现可拖拽的 TabControl,本文代码效果图如下:
使用 .Net Framework 4.8 创建名为 “TabMenu2” 的WPF模板项目,添加三个Nuget库:MaterialDesignThemes、MaterialDesignColors 和 Dragablz,其中 TabControl 的拖拽功能是由 Dragablz 库实现的。
以下为三个库具体版本:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Dragablz" version="0.0.3.203" targetFramework="net45" />
<package id="MaterialDesignColors" version="1.2.3-ci948" targetFramework="net48" />
<package id="MaterialDesignThemes" version="3.1.0-ci948" targetFramework="net48" />
</packages>
解决方案主要文件目录组织结构:
注:站长尝试使用 .NET CORE 3.1 创建WPF项目,但 Dragablz 库暂时未提供 .NET CORE 的版本。想着自己编译 Dragablz 的 .NET CORE 版本,奈何功力不够,改了一些源码,最后放弃了。文中代码及文末给出的 Demo 运行程序需要在 .NET Framework 4.0 运行时环境下运行,想尝试编译 Dragablz 库的朋友可在文末给出的链接中下载编译。
文件【App.xaml】,在 StartupUri 中设置启动的视图【MainWindow.xaml】,并在【Application.Resources】节点增加 MaterialDesignThemes 和 Dragablz 库的样式文件:
<Application x:Class="TabMenu2.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- primary color -->
<ResourceDictionary>
<!-- include your primary palette -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.purple.xaml" />
</ResourceDictionary.MergedDictionaries>
<!--
include three hues from the primary palette (and the associated forecolours).
Do not rename, keep in sequence; light to dark.
-->
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="{StaticResource Primary100}"/>
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="{StaticResource Primary100Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="{StaticResource Primary500}"/>
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="{StaticResource Primary500Foreground}"/>
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="{StaticResource Primary700}"/>
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="{StaticResource Primary700Foreground}"/>
</ResourceDictionary>
<!-- secondary colour -->
<ResourceDictionary>
<!-- include your secondary pallette -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/MaterialDesignColor.purple.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- include a single secondary accent color (and the associated forecolour) -->
<SolidColorBrush x:Key="SecondaryAccentBrush" Color="{StaticResource Accent200}"/>
<SolidColorBrush x:Key="SecondaryAccentForegroundBrush" Color="{StaticResource Accent200Foreground}"/>
</ResourceDictionary>
<!-- Include the Dragablz Material Design style -->
<ResourceDictionary Source="pack://application:,,,/Dragablz;component/Themes/materialdesign.xaml"/>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- tell Dragablz tab control to use the Material Design theme -->
<Style TargetType="{x:Type dragablz:TabablzControl}" BasedOn="{StaticResource MaterialDesignTabablzControlStyle}" />
</ResourceDictionary>
</Application.Resources>
</Application>
文件【MainWindow.xaml】,引入 MaterialDesignThemes 和 Dragablz 库的命名空间,【dragablz:TabablzControl】为 Dragablz 库封装的 TabControl,使用方式和原生控件类似,单项标签依然使用 TabItem,使用起来很简单,源码如下:
<Window x:Class="TabMenu2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz"
mc:Ignorable="d"
Height="600" Width="1080" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
MouseLeftButtonDown="Window_MouseLeftButtonDown" WindowStyle="None">
<Grid>
<Grid Height="60" VerticalAlignment="Top" Background="#FF9C27B0">
<TextBlock Text="Dotnet9.com:可拖拽TabControl" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22" FontFamily="Champagne & Limousines" />
<Button HorizontalAlignment="Right" VerticalAlignment="Center" Background="{x:Null}" BorderBrush="{x:Null}" Click="Close_Click">
<materialDesign:PackIcon Kind="Close"/>
</Button>
</Grid>
<Grid Margin="0 60 0 0">
<dragablz:TabablzControl>
<dragablz:TabablzControl.InterTabController>
<dragablz:InterTabController/>
</dragablz:TabablzControl.InterTabController>
<TabItem Header="首页">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center">
<Run Text="欢迎访问Dotnet9的博客:"/>
<Hyperlink Click="ShowWeb_Click" Tag="https://dotnet9.com">https://dotnet9.com</Hyperlink>
</TextBlock>
<WebBrowser Grid.Row="1" Margin="5" Source="https://dotnet9.com"/>
</Grid>
</TabItem>
<TabItem Header="设计">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="为用户体验服务!" FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<WebBrowser Grid.Row="1" Margin="5" Source="https://dotnet9.com"/>
</Grid>
</TabItem>
<TabItem Header="帮助">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center">
<Run Text="问答社区:"/>
<Hyperlink Click="ShowWeb_Click" Tag="https://dotnet9.com/questions-and-answers">https://dotnet9.com/questions-and-answers</Hyperlink>
</TextBlock>
<WebBrowser Grid.Row="1" Margin="5" Source="https://dotnet9.com/questions-and-answers"/>
</Grid>
</TabItem>
<TabItem>
<TabItem.Header>
<Image Source="https://img.dotnet9.com/logo.png"/>
</TabItem.Header>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30">
<Hyperlink Click="ShowWeb_Click" Tag="https://dotnet9.com">https://dotnet9.com</Hyperlink>
</TextBlock>
<WebBrowser Grid.Row="1" Margin="5" Source="https://dotnet9.com"/>
</Grid>
</TabItem>
</dragablz:TabablzControl>
</Grid>
</Grid>
</Window>
后台代码【MainWindow.xaml.cs】实现鼠标左键拖动窗体、右上角关闭窗体、超链接打开网站等功能:
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
private void Close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void ShowWeb_Click(object sender, RoutedEventArgs e)
{
Process.Start((sender as Hyperlink).Tag.ToString());
}
效果图实现代码在文中已经全部给出,可直接Copy,按解决方案目录组织代码文件即可运行。
演示Demo(点击下载->DragTabControl,2.39 MB)目录结构:
除非注明,文章均由 Dotnet9 整理发布,欢迎转载。
转载请注明本文地址:https://dotnet9.com/7391.html
时间如流水,只能流去不流回!
点击《【阅读原文】》,本站还有更多技术类文章等着您哦!!!
使用2个空格缩进
<ul>
<li>Fantastic</li>
<li>Great</li>
</ul>
.example {
color: blue;
}
只允许使用小写。
所有的代码都用小写字母:适用于元素名,属性,属性值(除了文本和CDATA), 选择器,特性,特性值(除了字符串)。
<!-- 不推荐 -->
<A HREF="/">Home</A>
<!-- 推荐 -->
<img src="google.png"
alt="Google">
建议删除行尾白空格。
<!-- 不推荐 -->
<p>What? </p>
<!-- 推荐 -->
<p>Yes please.</p>
如果没有特殊需求,一般采用utf-8编码。如果是cms站点,则遵守该站点的编码规则。
<!-- 网页编码 -->
<meta charset="utf-8">
尽可能的去解释你写的代码。说明该代码包括什么、目的是什么、能做什么、为什么使用它等。
注释是否需要详尽,取决于项目的复杂程度。
一般单行注释:
<!-- col -->
模块间注释:
<!-- news -->
<div class="news">
<h2>News</h2>
<p>...</p>
</div>
<!--/ news -->
循环注释:
<ul>
<!-- loop: new list -->
<li>new's title 1</li>
<li>new's title 2</li>
<li>new's title 3</li>
<li>new's title 4</li>
<li>new's title 5</li>
<!-- /loop: new list -->
</ul>
cms输出注释:
<!-- cms: news list -->
<ul>
<li>new's title 1</li>
<li>new's title 2</li>
<li>new's title 3</li>
<li>new's title 4</li>
<li>new's title 5</li>
</ul>
<!-- /cms: news list -->
Tab选项卡内容注释:
<!-- tab: news list -->
<div class="tab"></div>
<!-- /tab: news list -->
使用html5文档声明,不再使用XHTML(application/xhtml+xml)。
HTML5是目前所有HTML文档类型中的首选:
<!DOCTYPE html>
编写有效、正确的HTML代码,否则很难达到性能上的提升。
可以使用一些工具验证你的代码,如 W3C HTML validator
根据HTML各个元素的用途而去使用它们。
<!-- 不推荐 -->
<div class="col">
<div class="title">
news</div>
<p>list1</p>
<p>list2</p>
<p>list3</p>
</div>
<!-- 推荐 -->
<div class="col">
<h2 class="title">
news</h2>
<p>list1</p>
<p>list2</p>
<p>list3</p>
</div>
部分标签说明:
不推荐使用的标签:
给多媒体元素,比如canvas、videos、 images增加alt属性,提高可用性(特别是常用的img标签,尽可量得加上alt属性,提供图片的描述信息)。
<!-- 不推荐 -->
<img src="world.jpg">
<!-- 推荐 -->
<img src="world.jpg"
alt="our world images">
在样式表和脚本的标签中忽略type属性。
HTML5默认type为text/css和text/javascript类型,所以没必要指定。即便是老浏览器也是支持的。
<!-- 不推荐 -->
<link rel="stylesheet"
href="//www.google.com/css/maia.css"
type="text/css">
<script src="
//www.google.com/
js/gweb/analytics/autotrack.js"
type="text/javascript">
</script>
<!-- 推荐 -->
<link rel="stylesheet"
href="//www.google.com/css/maia.css">
<script src="
//www.google.com/
js/gweb/analytics/autotrack.js">
</script>
每个块元素、列表元素或表格元素都独占一行,每个子元素都相对于父元素进行缩进。按设计稿划分模块,尽量使页面模块化,模块与模块之前要有清晰的注释。
如上面页面框架,推荐写法:
<!-- hader -->
<div class="header">header</div>
<!-- /hader -->
<!-- nav -->
<div class="nav">nav</div>
<!-- /nav -->
<!-- main -->
<div class="main">
<!-- container -->
<div class="container">
<!--news-->
<div class="news">
<h2>news<h2>
<p>...</p>
</div>
<!--news-->
</div>
<!--/container-->
<!--sidebar-->
<div class="sidebar">
sidebar</div>
<!--sidebar-->
</div>
<!--/main-->
<!--footer-->
<div class="footer">
footer</div>
<!--/footer-->
保证整个页面在未加载样式表时仍有较好的层次清晰的页面结构。
<!-- 不推荐 -->
<div class="logo">My Site</div>
<div class="nav">
<a href="#">Home</a>
<a href="#">News</a>
<a href="#">Mobile</a>
</div>
<div class="news">
<div>News</div>
<a href="#">
news list 1</a>
<a href="#">
news list 2</a>
<a href="#">
news list 3</a>
</div>
<!-- 推荐 -->
<h1 class="logo">My Site</h1>
<ul class="nav">
<li><a href="#">
Home</a></li>
<li><a href="#">
News</a></li>
<li><a href="#">
Mobile</a></li>
</ul>
<div class="news">
<h2>News</h2>
<ul>
<li><a href="#">
news list 1</a>
</li>
<li><a href="#">
news list 2</a>
</li>
<li><a href="#">
news list 3</a>
</li>
</ul>
</div>
H标签使用
strong、b使用
将需要加粗的文字使用b标签来显示。
将需要强调的文字(主要指包含关键词的信息)使用strong标签来强调主要内容。
注:b是粗体标签,属于实体标签,它所包围的字符将被设为bold(粗体);strong 是加重语气标签,属于逻辑标签,它的作用是加强字符语气。
在很多情况下,a都要使用title来说明该链接的相关说明或目的意义。
例如:当使用overflow隐藏掉a中的溢出文字时,该a中的title是必不可少的,它可以告诉用户被隐藏掉的文字内容是什么;又或者当一个图片型链接出现时,该a中的title同样是必不可少的,它可以告诉用户这个图片链接是做什么用的。
注:仅在img里添加alt标签在火狐提示文字是出不来的,alt是图片加载失败或未加载完全时显示出来的提示文字,要想鼠标移上去显示提示信息应该用title,严谨的写法是img里加入alt和title这两个标签。
代码保持精简,最优化,这样搜索引擎才更喜欢。
*请认真填写需求信息,我们会在24小时内与您取得联系。