国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

C# WPF布局

這篇具有很好參考價值的文章主要介紹了C# WPF布局。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

布局:

1、Grid:

C# WPF布局,c#,wpf,ui

<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"

??????? Title="MainWindow" Height="450" Width="800">

??? <Grid Margin="0,0,12,0">

? ? ?<!--布局容器-->

??????? <Grid.RowDefinitions>

? ? ?<!--定義它的行以及它的高度-->

??????????? <RowDefinition Height="40"></RowDefinition>

??????????? <RowDefinition Height="Auto"></RowDefinition>

??????????? <RowDefinition Height="2*"></RowDefinition>

??????????? <RowDefinition Height="*"></RowDefinition>

??????? </Grid.RowDefinitions>

??????? <Grid.ColumnDefinitions>

? ? ?<!--定義它的列以及它的寬度-->

??????????? <ColumnDefinition Width="200"></ColumnDefinition>

??????????? <ColumnDefinition Width="200"></ColumnDefinition>

??????????? <ColumnDefinition Width="200"></ColumnDefinition>

??????????? <ColumnDefinition Width="200"></ColumnDefinition>

??????? </Grid.ColumnDefinitions>

? ?

??????? <Button Grid.Row="0" Grid.Column="2" Content="button1"></Button>

? ? ?<!--第0行第二列-->

??????? <Button Grid.Row="0" Grid.Column="1" Content="button3"></Button>

? ? ?<!--第0行第1列-->

??????? <Button Grid.Row="1" Content="button2"></Button>

? ? ?<!--第一行-->

??????? <Button Grid.Row="2" Content="button4"></Button>

? ? ?<!--//第二行-->

??????? <Button Grid.Row="3" Content="button5"></Button>

? ? ?<!--//第三行-->

??? </Grid>

</Window>文章來源地址http://www.zghlxwxcb.cn/news/detail-855215.html

StackPanel:按行按列排序

C# WPF布局,c#,wpf,ui

<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"

??????? Title="MainWindow" Height="450" Width="800">

? ?2、 <Grid>

??????? <StackPanel? Name="Stcak1" Orientation="Horizontal">

??????????? <Button Content="button1"/>

??????????? <Button Content="button2"/>

??????? </StackPanel>

??????? <StackPanel x:Name="Stack2" Orientation="Vertical">

??????????? <Button Content="button3"></Button>

??????????? <Button Content="button4"></Button>

??????????? <Button Content="button5"></Button>

??????? </StackPanel>

??????? <StackPanel Name="stack3" Orientation="Horizontal" FlowDirection="RightToLeft">

??????????? <Button Content="button6"></Button>

??????????? <Button Content="button7"></Button>

??????? </StackPanel>

??? </Grid>

3、WrapPanel://自動換行環(huán)列

C# WPF布局,c#,wpf,ui

<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"

??????? Title="MainWindow" Height="450" Width="800">

??? <WrapPanel Orientation="Horizontal">

??????? <Button Content="button 150" Width="150"></Button>

??????? <Button Content="button 200" Width="200"></Button>

??????? <Button Content="button 150" Width="150"></Button>

??????? <Button Content="button 200" Width="200"></Button>

??????? <Button Content="button 150" Width="150"></Button>

??? </WrapPanel>

</Window>

DockPanel:

C# WPF布局,c#,wpf,ui

??? <DockPanel>

??????? <Button Content="左"? DockPanel.Dock="Left"></Button>

??????? <Button Content="下"? DockPanel.Dock="Bottom" ></Button>

??????? <Button Content="右"? DockPanel.Dock="Right"></Button>

??????? <Button Content="上"? DockPanel.Dock="Top" ></Button>

??? </DockPanel>

4、UniformGrid://按照輸入順序排列到容器當(dāng)中

C# WPF布局,c#,wpf,ui

??? <UniformGrid >

??????? <Button Content="Button"></Button>

??????? <Button Content="Button1"></Button>

??????? <Button Content="Button2"></Button>

??????? <Button Content="Button3"></Button>

??????? <Button Content="Button4"></Button>

??? </UniformGrid>

C# WPF布局,c#,wpf,ui

<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"

??????? Title="MainWindow" Height="450" Width="800">

??? <Grid>

??????? <Canvas>

??????????? <Button?? Content="Button1" Canvas.Left="50"? Canvas.Top="50"></Button>

??????????? <Button?? Content="Button2" Canvas.Right="50" Canvas.Top="50" ></Button>

??????????? <Button?? Content="Button3" Canvas.Left="50"? Canvas.Bottom="50" ></Button>

??????????? <Button?? Content="Button3" Canvas.Left="50"? Canvas.Bottom="50" ></Button>

??????? </Canvas>

??? </Grid>

</Window>

ScrollViewer:滑動框

C# WPF布局,c#,wpf,ui

??? <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">

??????? <Button Content="Button" Width="800" Height="800"></Button>

??? </ScrollViewer>

ViewBox:

??? <Grid>

??????? <Grid.ColumnDefinitions>

??????????? <ColumnDefinition></ColumnDefinition>

??????? </Grid.ColumnDefinitions>

??????? <Grid.RowDefinitions>

??????????? <RowDefinition></RowDefinition>

??????? </Grid.RowDefinitions>

??????? <Viewbox Grid.Row="0" Grid.Column="0" Stretch="None">

??????????? <Button Width="100" Height="50" Content="None"></Button>

??????? </Viewbox>

??????? <Viewbox Grid.Row="0" Grid.Column="1" Stretch="Uniform">

??????????? <Button Width="100" Height="50" Content="Uniform"></Button>

??????? </Viewbox>

??? </Grid>

樣式:

C# WPF布局,c#,wpf,ui

內(nèi)部樣式:

<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"

??????? Title="MainWindow" Height="450" Width="800">

??? <Window.Resources>

??????? <Style TargetType="Button">/設(shè)置樣式的類型,全局樣式

??????????? <Setter Property="Background" Value="WhiteSmoke"></Setter>//設(shè)置背景屬性的樣式

??????????? <Setter Property="FontSize"? Value="20"></Setter>//設(shè)置文本字體的樣式

??????????? <Setter Property="Margin"? Value="10, 20"></Setter>//設(shè)置邊框的外部樣式

??????? </Style>

??????? <Style x:Key="loginStyle" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">//綁定單個樣式

??????????? <Setter Property="Background" Value="CadetBlue"></Setter>

??????? </Style>

??? </Window.Resources>

??? <Grid>

??????? <Grid.ColumnDefinitions>

??????????? <ColumnDefinition></ColumnDefinition>

??????????? <ColumnDefinition></ColumnDefinition>

??????????? <ColumnDefinition></ColumnDefinition>

??????? </Grid.ColumnDefinitions>

??????? <Grid.RowDefinitions>

??????????? <RowDefinition></RowDefinition>

??????????? <RowDefinition></RowDefinition>

??????????? <RowDefinition></RowDefinition>

??????? </Grid.RowDefinitions>

??????? <Button Style="{StaticResource loginStyle}" Content="Button1" Grid.Column="0" Grid.Row="1" Width="Auto" Height="Auto" ></Button>

??????? <Button Content="Button1" Grid.Column="0" Grid.Row="2" Width="Auto" Height="Auto" ></Button>

??????? <Button Content="Button1" Grid.Column="0" Grid.Row="0" Width="Auto" Height="Auto" ></Button>

??? </Grid>

</Window>?

外部樣式:

首先創(chuàng)建一個xaml文件

C# WPF布局,c#,wpf,ui

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

??????????????????? xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

???

??????? <Style TargetType="Button">

??????????? <Setter Property="Background" Value="WhiteSmoke"></Setter>

??????????? <Setter Property="FontSize"? Value="20"></Setter>

??????????? <Setter Property="Margin"? Value="10, 20"></Setter>

??????? </Style>

??????? <Style x:Key="loginStyle" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">

??????????? <Setter Property="Background" Value="CadetBlue"></Setter>

??????? </Style>

</ResourceDictionary>

然后在App.xaml種添加

引用路徑

<Application x:Class="WpfApp2.App"

???????????? xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

???????????? xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

???????????? xmlns:local="clr-namespace:WpfApp2"

???????????? StartupUri="MainWindow.xaml">

??? <Application.Resources>

??????? <ResourceDictionary>

??????????? <ResourceDictionary.MergedDictionaries>

??????????????? <ResourceDictionary Source="/WpfApp2;component/Dictionary1.xaml"/>

??????????? </ResourceDictionary.MergedDictionaries>

??????? </ResourceDictionary>

??? </Application.Resources>

</Application>

C# WPF布局,c#,wpf,ui

<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"

??????? Title="MainWindow" Height="450" Width="800">

??? <Grid>

??????? <Grid.ColumnDefinitions>

??????????? <ColumnDefinition></ColumnDefinition>

??????????? <ColumnDefinition></ColumnDefinition>

??????????? <ColumnDefinition></ColumnDefinition>

??????? </Grid.ColumnDefinitions>

??????? <Grid.RowDefinitions>

??????????? <RowDefinition></RowDefinition>

??????????? <RowDefinition></RowDefinition>

??????????? <RowDefinition></RowDefinition>

??????? </Grid.RowDefinitions>

??????? <Button Style="{StaticResource loginStyle}" Content="Button1" Grid.Column="0" Grid.Row="1" Width="Auto" Height="Auto" ></Button>

??????? <Button Content="Button1" Grid.Column="0" Grid.Row="2" Width="Auto" Height="Auto" ></Button>

??????? <Button Content="Button1" Grid.Column="0" Grid.Row="0" Width="Auto" Height="Auto" ></Button>

??? </Grid>

</Window>

自定義樣式模板及觸發(fā)器

<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"

??????? Title="MainWindow" Height="450" Width="800">

??? <Grid>

??????? <Button Content="自定義按鈕"? Height="100" Width="200" Background="#0078d4" FontSize="50" Foreground="WhiteSmoke" BorderBrush="Aqua" BorderThickness="1">

??????????? <Button.Template>

??????????????? <ControlTemplate TargetType="{x:Type Button}">

??????????????????? <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="20">

??????????????????????? <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>

??????????????????? </Border>

??????????????? </ControlTemplate>??

??????????? </Button.Template>

??????? </Button>

??? </Grid>

</Window>

C# WPF布局,c#,wpf,ui

<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"

??????? Title="MainWindow" Height="450" Width="800">

??? <Grid>

??????? <Button Content="自定義按鈕"? Height="100" Width="200" Background="#0078d4" FontSize="50" Foreground="WhiteSmoke" BorderBrush="Aqua" BorderThickness="1">

??????????? <Button.Template>

??????????????? <ControlTemplate TargetType="{x:Type Button}">

??????????????????? <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="20">

?????????????

??????????????????????? <TextBlock Text="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>

??????????????????? </Border>

??????????????? </ControlTemplate>??

??????????? </Button.Template>

??????? </Button>

??? </Grid>

</Window>

觸發(fā)器綁定:

<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"

??????? Title="MainWindow" Height="450" Width="800">

??? <Grid>

??????? <Button Content="自定義按鈕"? Height="100" Width="200" Background="#0078d4" FontSize="50" Foreground="WhiteSmoke" BorderBrush="Aqua" BorderThickness="1">

??????????? <Button.Template>

??????????????? <ControlTemplate TargetType="{x:Type Button}">

??????????????????? <Border x:Name="boder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="20">

?????????????

??????????????????????? <TextBlock x:Name="txt" Text="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>

??????????????????? </Border>

??????????????????? <ControlTemplate.Triggers>

??????????????????????? <Trigger Property="IsMouseOver" Value="true">//綁定鼠標(biāo)移動

??????????????????????????? <Setter TargetName="boder" Property="Background" Value="Blue"/>

???????????????????????? <Setter TargetName="txt" Property="FontSize" Value="20"/>

??????????????????????? </Trigger>

??????????????????????? <Trigger Property="IsPressed" Value="true">//綁定鼠標(biāo)點下去的

??????????????????????????? <Setter TargetName="txt" Property="Background" Value="red"/>

???????????????????????? <Setter TargetName="txt" Property="FontSize" Value="20"/>

??????????????????????? </Trigger>

??????????????????? </ControlTemplate.Triggers>

??????????????? </ControlTemplate>??

??????????? </Button.Template>

??????? </Button>

??? </Grid>

</Window>

到了這里,關(guān)于C# WPF布局的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • WPF 組態(tài)軟件實現(xiàn)思路(WPF控件可視化布局)

    WPF 組態(tài)軟件實現(xiàn)思路(WPF控件可視化布局)

    一、實現(xiàn)控件選中及自由拖動 二、實現(xiàn)控件對齊功能 三、實現(xiàn)對齊輔助線功能 四、實現(xiàn)框選功能 GitHub地址點此 屬性編輯控件基于Devexpress V21.2.3 控件庫,如需編譯需購買及安裝 Devexpress V21.2.3 開發(fā)庫 腳本編輯基于AvalonEdit開源庫 https://github.com/icsharpcode/AvalonEdit 圖標(biāo)控件基于

    2024年02月04日
    瀏覽(66)
  • WPF 零基礎(chǔ)入門筆記(1):WPF靜態(tài)頁面,布局+樣式+觸發(fā)器

    WPF 零基礎(chǔ)入門筆記(1):WPF靜態(tài)頁面,布局+樣式+觸發(fā)器

    WPF 零基礎(chǔ)入門筆記(0):WPF簡介 WPF MaterialDesign 初學(xué)項目實戰(zhàn)(0):github 項目Demo運行 WPF MaterialDesign 初學(xué)項目實戰(zhàn)(1)首頁搭建 WPF MaterialDesign 初學(xué)項目實戰(zhàn)(2)首頁導(dǎo)航欄樣式 WPF MaterialDesign 初學(xué)項目實戰(zhàn)(3)動態(tài)側(cè)邊欄 WPF MaterialDesign 初學(xué)項目實戰(zhàn)(4)側(cè)邊欄路由管理

    2024年02月11日
    瀏覽(51)
  • (四)WPF - 布局

    WPF 布局包括兩個階段: 一個測量階段和排列階段 在測量階段,容器遍歷所有子元素,并詢問子元素它們所期望的尺寸。 在排列階段,容器在合適的位置放置子元素。(每個元素都被其父元素告知它自己的尺寸是多少以設(shè)定尺寸和位置) 這兩個階段讓父和子元素能夠協(xié)商需

    2024年02月10日
    瀏覽(26)
  • WPF_布局基礎(chǔ)

    WPF_布局基礎(chǔ)

    定義由列和行組成的靈活的網(wǎng)格區(qū)域。 行 列 背景 尺寸 自動適應(yīng):以所在行的元素最高尺寸為標(biāo)準(zhǔn)來定義行高。 絕對尺寸:給指定數(shù)值或者比例來定義行高。 跨行跨列:類似合并方格。 將子元素排列成水平或垂直的一行(默認(rèn):垂直)。 將子元素按從左到右的順序定位,

    2024年02月10日
    瀏覽(23)
  • WPF 布局

    WPF 布局

    WPF中所有布局如下,我們一一嘗試實現(xiàn),本文檔主要以圖形化的形式展示每個布局的功能。 布局 :?Border、?BulletDecorator、?Canvas、?DockPanel、?Expander、?Grid、?GridView、?GridSplitter、?GroupBox、?Panel、?ResizeGrip、?Separator、?ScrollBar、?ScrollViewer、?StackPanel、?Thumb、?Viewbox、?

    2024年02月02日
    瀏覽(25)
  • WPF網(wǎng)格拖動自動布局效果

    WPF網(wǎng)格拖動自動布局效果

    使用Canvas和鼠標(biāo)相關(guān)事件實現(xiàn)如下的效果: XAML代碼: C#代碼 項目地址github

    2024年02月11日
    瀏覽(22)
  • WPF 入門筆記 - 02 - 布局綜合應(yīng)用

    WPF 入門筆記 - 02 - 布局綜合應(yīng)用

    本篇博文對接上篇末尾處WPF常用布局控件的綜合應(yīng)用,為痕跡g布局控件介紹課后作業(yè)的一個思路方法。 首先來談一談布局原則: WPF 窗口只能包含一個元素(Window元素屬于內(nèi)容控件,內(nèi)容控件只允許有一個子元素),所以我們得在窗口中放置一個容器,才能使我們的窗口放置更

    2024年02月06日
    瀏覽(29)
  • WPF 啟動項目 Grid、StackPanel 布局

    WPF 啟動項目 Grid、StackPanel 布局

    1.固定像素布局 Width = “200” 2.比例布局 Width = “1*” 3.內(nèi)容長度自動布局 Width = “AUTO”

    2024年02月22日
    瀏覽(20)
  • WPF ListView 自定義Item布局

    ViewModel : View:

    2024年02月16日
    瀏覽(18)
  • WPF 入門筆記 - 01 - 入門基礎(chǔ)以及常用布局

    WPF 入門筆記 - 01 - 入門基礎(chǔ)以及常用布局

    ??本篇為學(xué)習(xí)博客園大佬圣殿騎士的《WPF基礎(chǔ)到企業(yè)應(yīng)用系列》以及部分DotNet菜園的《WPF入門教程系列》所作筆記,對應(yīng)圣殿騎士《WPF基礎(chǔ)到企業(yè)應(yīng)用系列》第 1 - 6 章之間內(nèi)容,包括 WPF 項目結(jié)構(gòu)、程序的啟動和關(guān)閉、程序的生命周期、繼承關(guān)系以及常見的布局控件及其應(yīng)用

    2024年02月05日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包