WPF中的DockPanel是提供对元素进行左边停靠、右边停靠、顶部停靠、底部停靠、填充停靠操作的布局控件,通过设置DockPanel.Dock属性决定元素的停靠位置,LastChildFill属性默认为 ://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <DockPanel LastChildFill="True"> <Button Content="Button1" DockPanel.Dock="Top"/> <Button Content ="Button2" DockPanel.Dock="Bottom"/> <Button Content="Button3" DockPanel.Dock="Left"/> <Button Content="Button4" DockPanel.Dock="Right"/> <Button Content="Button5" /> </DockPanel
如: 1: <DockPanel > 2: <Button Content="ButtonA" Width="70" DockPanel.Dock="Top" /> 3: <Button Content ="ButtonB" Width="70" HorizontalAlignment="Right" DockPanel.Dock="Top" /> 4: <Button Content="ButtonC " Margin="10" DockPanel.Dock="Top" /> 5: <Button Content="ButtonD" DockPanel.Dock="Left" /> 6: <Button Content="ButtonE" DockPanel.Dock="Right" /> 7: <Button Content="ButtonF" DockPanel.Dock="Bottom" /> 8: <Button Content="ButtonG" /> 9: </DockPanel> 发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/163337.html
DockPanel DockPanel停靠容器,专门负责自适应窗口的布局,之前我们介绍了DockPanel的布局设置,这里再回顾下: <DockPanel> <StackPanel DockPanel.Dock=”Top” Height=”0″> </StackPanel> <StackPanel DockPanel.Dock > 上面的DockPanel在进行自适应布局时,默认最后的一个区域时默认填充,可以理解为fill。 当然,这个页面的整体,我们也可以采用DockPanel进行布局,布局的效果,完全可以达到上述效果,下面我们来使用DockPanel来对整体进行布局吧。 最终的代码如下: <DockPanel> <StackPanel DockPanel.Dock=”Top” Height=”100″> <Grid
DockPanel DockPanel停靠容器,专门负责自适应窗口的布局,之前我们介绍了DockPanel的布局设置,这里再回顾下: <DockPanel> <StackPanel DockPanel.Dock=”Top” Height=”0″> </StackPanel> <StackPanel DockPanel.Dock > 上面的DockPanel在进行自适应布局时,默认最后的一个区域时默认填充,可以理解为fill。 当然,这个页面的整体,我们也可以采用DockPanel进行布局,布局的效果,完全可以达到上述效果,下面我们来使用DockPanel来对整体进行布局吧。 最终的代码如下: <DockPanel> <StackPanel DockPanel.Dock=”Top” Height=”100″> <Grid
weiFenLuo.winFormsUI.Docking.dll是开源项目DockPanel Suite的一个类库,可以实现像Visual Studio的窗口停靠、拖拽等功能。 4.工具箱—>右键—>选择项—>.net组件—>浏览—>weiFenLuo.winFormsUI.Docking.dll—>在工具箱出现dockPanel。 5.将dockPanel拖到窗体Form1上,设置Dock属性,我设置的是:Fill。 停靠窗体: 1.新建一个WinForm窗体Form2。 private void Form1_Load(object sender, EventArgs e) { Form2 form2 = new Form2(); form2.Show(this.dockPanel1 ); form2.DockTo(this.dockPanel1, DockStyle.Left); } 其中dockPanel1是父窗口中DockPanel的名称。
(5)一定要先设置Form1的IsMdiContainer属性为True, 再放置一个dockPanel控件和Vs2015BlueTheme到Form1上,设置dockPanel1的Dock为Fill, 这以上步骤仅是把DockPanel控件添加到工具箱中。 FormBorderStyle设置为 5.将dockPanel拖放到Mainwnd中,设置dockpanel的相关属性:dockPanel.Dock=Fill (以及DocumentStyle为DockingMdi ); frmHistory.Show(this.dockPanel); frmStock.Show(this.dockPanel); frmProduct.Show(this.dockPanel); frmCustomer.Show(this.dockPanel); frmOrder.Show
一、DockPanel控件详解 WPF中的DockPanel控件是一种面板控件,它可以将其子控件沿着指定的边缘对齐并填充整个可用空间。 Right:子控件应该放置在DockPanel的右侧。 Top:子控件应该放置在DockPanel的顶部。 Bottom:子控件应该放置在DockPanel的底部。 下面是一个DockPanel控件的示例: <DockPanel> <Button DockPanel.Dock="Top" Content="Top" /> <Button DockPanel.Dock Dock:指定元素在DockPanel中的位置。可以将元素靠左、靠右、靠上或靠下排列。 Background:指定DockPanel的背景颜色。 Width:指定DockPanel的宽度。 Height:指定DockPanel的高度。 VerticalAlignment:指定DockPanel在父元素中的垂直对齐方式。
:沿着一条外边缘来拉伸所包含的控件,也就类似于许多窗口顶部的工具栏: <DockPanel LastChildFill="False" Background="Pink" > < Button Content="上" DockPanel.Dock="Top" Background="Blue"/> <Button Content="左" DockPanel.Dock ="Left" Background="Yellow"/> <Button Content="下" DockPanel.Dock="Bottom" Background="Red"/> <Button Content="右" DockPanel.Dock="Right" Background="Black"/> </DockPanel> //Dock 用于设置其对齐方式,有"Top","Left","Bottom","Right"四个属性值 LastChildFill:获取或设置一个值,该值指示 System.Windows.Controls.DockPanel
Margin="0"> <ScrollViewer DockPanel.Dock="Top" ="Left" /> </DockPanel> </Border> LastChildFill="True"> <TextBlock DockPanel.Dock="Left" Text="{Binding > <Rectangle DockPanel.Dock="Left" Fill="Black" Width="1"></Rectangle > <TextBlock DockPanel.Dock="Left" Text="{Binding Path=Description
1)UI部分 主要代码如下: <DockPanel> <TextBlock Text="v2023.09.27.0001" DockPanel.Dock="Bottom" HorizontalAlignment > <Border BorderBrush="{DynamicResource BorderBrush}" BorderThickness="0,0,1,0"> <DockPanel Width="192" Background="{DynamicResource SecondaryBackgroundBrush}"> <Border DockPanel.Dock > </TabItem.Header> <DockPanel> <hc:UniformSpacingPanel Margin="33,24,33,0 > </TabItem.Header> <<em>DockPanel</em>> <hc:UniformSpacingPanel Margin="33,24,33,0
XML 数据绑定是最原始的种类的,比如 WPF 里面的数据绑定: <DockPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:c="clr-namespace:SDKSample"> <DockPanel.Resources > <c:MyData x:Key="myDataSource"/> </DockPanel.Resources> <DockPanel.DataContext> <Binding Source="{StaticResource myDataSource}"/> </DockPanel.DataContext> <Button Background="{Binding Path </Button> </<em>DockPanel</em>> 这种语法无比啰嗦累赘,我不喜欢,虽说很多 DSL 都是这样设计的。
DockPanel。可以指定上下左右中五个方位的组件。 Grid。网格布局,可以按照网格形式排列组件。 现在返回来看看这个浏览器的布局。首先第一行是按钮和地址栏,第二行就是浏览器控件了。 所以第一行本身也需要使用DockPanel来实现。 最后来看看相应的XAML代码,虽然说得比较多,但是代码倒是很少。 <DockPanel> <DockPanel DockPanel.Dock="Top"> <Button Name="ForwardButton" Content="前进" Click > <WebBrowser Name="BrowserControl" /> </DockPanel> 控件 其实关于控件我倒是没什么说的。 <DockPanel> <DockPanel DockPanel.Dock="Top"> <Button Name="ForwardButton" Content="前进" Click
拖拉布局控件"WeifenLuo.WinFormsUI.Docking.DockPanel"到主窗体MainForm中,并设置下面几个属性: Dock为Fill、DocumentStyle为DockingMdi mainToolWin.Show(this.dockPanel, DockState.DockLeft); 3、对于工具窗口我们已经完成了,但是主业务窗口还没有做,也就是下面的部分内容。 , DockState.DockLeft); frmComingCall.Show(this.dockPanel); frmDeliving.Show(this.dockPanel ); frmHistory.Show(this.dockPanel); frmStock.Show(this.dockPanel); frmProduct.Show(this.dockPanel); frmCustomer.Show(this.dockPanel); frmOrder.Show
Dockpanel布局 直接指定控件的位置 <Window x:Class="day25test02.MainWindow" xmlns="http://schemas.microsoft.com mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> //Dockpanel 布局,直接指定控件的位置 <DockPanel> <Menu DockPanel.Dock="Top"> <MenuItem Header " mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> <DockPanel ="Bottom"></TextBox> </DockPanel> </Grid> </Window> 多窗口 几个常用属性: ResizeMode = NoResize; 不能缩放
--<DockPanel Margin="10" Background="Azure" LastChildFill="True"> <Button DockPanel.Dock="Top " Background="Red">Top Button</Button> <Button DockPanel.Dock="Left" Background="Gray">Left Button </Button> <Button DockPanel.Dock="Right" Background="Green">Right Button</Button> <Button DockPanel.Dock="Bottom" Background="White">Bottom Button</Button> <Button>Remaining Button< /Button> </DockPanel>--> <!
://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="283"> <DockPanel > <StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" HorizontalAlignment="Right"> Button" Margin="5,10,10,10"/> </StackPanel> <TextBox TextWrapping="Wrap" Text="TextBox" DockPanel.Dock ="Top"/> </DockPanel> </Window>
3.5 DockPanel 布局控件 DockPanel面板定义一个区域,在此区域中,你可以使子元素通过锚点的形式进行排列。DockPanel类似于WinForm中Dock属性的功能。 对于在DockPanel中的元素的停靠可以通过Panel.Dock的附加属性来设置,如果设置LastChildFill属性为true,则最后一个元素将填充剩余的所有空间。 Margin="10" Background="Azure" LastChildFill="True"> <Button DockPanel.Dock="Top" Background ="Red">Top Button</Button> <Button DockPanel.Dock="Left" Background="Gray">Left Button</Button > <Button DockPanel.Dock="Right" Background="Green">Right Button</Button> <Button DockPanel.Dock
Static RelativeSource.TemplatedParent}}" > <DockPanel DockPanel.Dock="Top" Name="dpBtn"> <DockPanel.Background> RelativeSource={x:Static RelativeSource.TemplatedParent}}"></TextBlock> </DockPanel ----------------------------------------------------------------------- 现在我们使用下我们制作好的自定义控件,代码如下所示: <DockPanel Fill" ForeImage="/Image/篮子.png" Background="Gray" MouseOverBackColor="Brown"/> </StackPanel> </DockPanel
" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> <DockPanel DockPanel.Dock="Top" > <DockPanel.Resources> <Style TargetType="{x:Type <Setter Property="Padding" Value="4,2" /> </Style> </DockPanel.Resources > <smith:HtmlEditor x:Name="Editor" DockPanel.Dock="Top"/> </DockPanel> </Grid
--沿着上边缘拉伸--> <Button Content="Top" DockPanel.Dock="Top"></Button> <! --沿着下边缘拉伸--> <Button Content="Bottom" DockPanel.Dock="Bottom"></Button> <! --沿着左边缘拉伸--> <Button Content="Left" DockPanel.Dock="Left"></Button> <! --沿着右边缘拉伸--> <Button Content="Right" DockPanel.Dock="Right"></Button> <! --最后一个元素默认填充满整个容器剩余的空间--> <Button Content="默认最后一个自适应"></Button> </DockPanel> </Window> Grid表格布局 Grid