当前位置:   article > 正文

wpf布局学习二 wpf xaml 与android xml界面对比, C++图片旋转与缩放好复杂放弃_wpf是否类似于android界面开发

wpf是否类似于android界面开发

弄不明白的事,还是不要去做。

没懂清楚原理,不要尝试去修改。浪费时间。

 wpf布局学习二

 

  1. <Window x:Class="WpfM20UpdateFW.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:local="clr-namespace:WpfM20UpdateFW"
  7. mc:Ignorable="d"
  8. Title="M20 Update Firmware V1.0" Height="450" Width="800">
  9. <Grid>
  10. <Grid ShowGridLines="false" MinWidth="20" FocusManager.FocusedElement="{Binding ElementName=download}">
  11. <Grid.RowDefinitions>
  12. <RowDefinition Height="0.2*"></RowDefinition>
  13. <RowDefinition Height="0.8*"></RowDefinition>
  14. </Grid.RowDefinitions>
  15. <Grid.ColumnDefinitions>
  16. <ColumnDefinition Width="0.2*"></ColumnDefinition>
  17. <ColumnDefinition Width="0.8*"></ColumnDefinition>
  18. </Grid.ColumnDefinitions>
  19. <Button x:Name="download" Grid.Row="0" Grid.Column="0" Click="Button_Click">Download FW</Button>
  20. <ProgressBar x:Name="Progress" Grid.Row="0" Grid.Column="1" />
  21. <TextBox x:Name="Log" Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding ElementName=Progress,Path=Value}"/>
  22. </Grid>
  23. </Grid>
  24. </Window>
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace WpfM20UpdateFW
  16. {
  17. /// <summary>
  18. /// MainWindow.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class MainWindow : Window
  21. {
  22. public MainWindow()
  23. {
  24. InitializeComponent();
  25. }
  26. private void Button_Click(object sender, RoutedEventArgs e)
  27. {
  28. // MessageBox.Show("start");
  29. // TextBox textBox = log as TextBox;
  30. ++Progress.Value;
  31. if (Progress.Value == Progress.Maximum)
  32. {
  33. Progress.Value=Progress.Minimum;
  34. }
  35. //Log.Text = ""+ Progress.Value;
  36. }
  37. }
  38. }

1.绑定 以同步更新 "{Binding ElementName=元素名,Path=元素属性}"

2.在父类容器中通过附加属性FocusManager.FocusedElement来绑定需要强制获得焦点的控件        <Grid ShowGridLines="false" MinWidth="20" FocusManager.FocusedElement="{Binding ElementName=download}">

3.Grid跨列Grid.ColumnSpan="2"  跨行Grid.RowSpan="2"   即跨2行。

4.放置在Grid面板中的控件元素都必须显示采用Row和Column附加属性定义其放置所在的行和列,这两个属性的值都是从0开始的索引数,如果没有显式设置任何行或列,Grid将会隐式地将控件加入在第0行第0列。

wpf xaml 与android xml界面对比  这两很相似。

1.框架布局 (基本也能对应)

android:linear_layout

wpf:stack_Panel

怎么只有Grid才能用比例?Width="0.8*"

Grid:放置在Grid面板中的控件元素都必须显示采用Row和Column附加属性定义其放置所在的行和列,这两个属性的值都是从0开始的索引数,如果没有显式设置任何行或列,Grid将会隐式地将控件加入在第0行第0列。这与其他控件不同,不能把子控件直接拖在格子里。

 

 

2.各种控件(都有,不说了)

3.各控件的方法名(基本一样)

4.各控件的属性名(wpf这有点坑)

拖控件后不自动生成Name,必须手工加,加完才能通过这个Name在代码操控。

  1. // TextBox textBox = log as TextBox;
  2. // textBox.Text = "chenhao";
  3. log.Text = "chenhao";

有人说 

这是WPF故意的,后端默认不直接访问UI控件,而是由前端绑定后端的属性,这样的好处就是前后端解耦,可以更换不同UI

自动生成也没有影响啊!!!!用惯了多年的winForm,特别不习惯这样。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/804312
推荐阅读
相关标签
  

闽ICP备14008679号