MainWindow.xaml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <Window x:Class="MvvmScaffoldFrame48.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:MvvmScaffoldFrame48"
  7. mc:Ignorable="d"
  8. Title="MainWindow" Height="450" Width="800">
  9. <Grid>
  10. <Grid.ColumnDefinitions>
  11. <ColumnDefinition Width="*" />
  12. <ColumnDefinition Width="*" />
  13. </Grid.ColumnDefinitions>
  14. <StackPanel Grid.Column="0">
  15. <ToolBar>
  16. <Label Content="姓名:"></Label>
  17. <TextBox Text="{Binding Name}" Width="50"></TextBox>
  18. <Label Content="邮箱:"></Label>
  19. <TextBox Text="{Binding Email}" Width="100"></TextBox>
  20. <Button Content="添加"
  21. Command="{Binding AddUserCommand }"></Button>
  22. <Button Content="测试"
  23. Command="{Binding TestCommand }"></Button>
  24. </ToolBar>
  25. <StackPanel>
  26. <DataGrid ItemsSource="{Binding Users}"></DataGrid>
  27. </StackPanel>
  28. </StackPanel>
  29. <Grid Grid.Column="1">
  30. <StackPanel Height="30" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center">
  31. <Label Content="红绿灯演示"></Label>
  32. <Ellipse Width="20" Height="20" Margin="48,0,0,0" >
  33. <Ellipse.Style>
  34. <Style TargetType="Ellipse">
  35. <Setter Property="Fill" Value="Red" />
  36. <Style.Triggers>
  37. <DataTrigger Binding="{Binding StaticTest}" Value="True">
  38. <Setter Property="Fill" Value="Green" />
  39. </DataTrigger>
  40. </Style.Triggers>
  41. </Style>
  42. </Ellipse.Style>
  43. </Ellipse>
  44. </StackPanel>
  45. <StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,40,0,0" Height="30">
  46. <Label Content="可以更改背景颜色的ComboBox:"/>
  47. <ComboBox Height="40" Width="140" ItemsSource="{Binding FormulationItems}" HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalContentAlignment="Center" FontSize="20">
  48. <ComboBox.Template>
  49. <ControlTemplate TargetType="ComboBox">
  50. <Grid>
  51. <ToggleButton
  52. Foreground="White"
  53. IsChecked="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
  54. ClickMode="Press">
  55. <ToggleButton.Template>
  56. <ControlTemplate TargetType="ToggleButton">
  57. <Border x:Name="Border" Background="#FF0087FF" BorderBrush="#FFABADB3" BorderThickness="1">
  58. <Grid>
  59. <Grid.ColumnDefinitions>
  60. <ColumnDefinition />
  61. <ColumnDefinition Width="20" />
  62. </Grid.ColumnDefinitions>
  63. <ContentPresenter Grid.Column="0" Margin="3" />
  64. <Path x:Name="Arrow" Grid.Column="1"
  65. Fill="White"
  66. HorizontalAlignment="Center"
  67. VerticalAlignment="Center"
  68. Data="M 0 0 L 4 4 L 8 0 Z" />
  69. </Grid>
  70. </Border>
  71. <ControlTemplate.Triggers>
  72. <Trigger Property="IsMouseOver" Value="True">
  73. <Setter TargetName="Border" Property="Background" Value="LightBlue" />
  74. </Trigger>
  75. </ControlTemplate.Triggers>
  76. </ControlTemplate>
  77. </ToggleButton.Template>
  78. </ToggleButton>
  79. <ContentPresenter x:Name="ContentSite"
  80. IsHitTestVisible="False"
  81. Content="{TemplateBinding SelectionBoxItem}"
  82. ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
  83. Margin="3,3,23,3"
  84. VerticalAlignment="Center"
  85. HorizontalAlignment="Left"
  86. TextBlock.Foreground="White"/>
  87. <Popup x:Name="Popup"
  88. Placement="Bottom"
  89. IsOpen="{TemplateBinding IsDropDownOpen}"
  90. AllowsTransparency="True"
  91. Focusable="False"
  92. PopupAnimation="Slide">
  93. <Border x:Name="DropDownBorder"
  94. Background="#FF0087FF"
  95. BorderBrush="#FF0087FF"
  96. BorderThickness="1">
  97. <ScrollViewer Margin="0,3,0,3"
  98. SnapsToDevicePixels="True">
  99. <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" />
  100. </ScrollViewer>
  101. </Border>
  102. </Popup>
  103. </Grid>
  104. </ControlTemplate>
  105. </ComboBox.Template>
  106. <ComboBox.ItemContainerStyle>
  107. <Style TargetType="ComboBoxItem">
  108. <Setter Property="Background" Value="#FF0087FF" />
  109. <Setter Property="Foreground" Value="White" />
  110. <Style.Triggers>
  111. <Trigger Property="IsHighlighted" Value="True">
  112. <Setter Property="Background" Value="LightBlue" />
  113. </Trigger>
  114. </Style.Triggers>
  115. </Style>
  116. </ComboBox.ItemContainerStyle>
  117. </ComboBox>
  118. </StackPanel>
  119. <StackPanel Orientation ="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,80,0,0">
  120. <Label Content="圆角按钮:"/>
  121. <Button Content="圆角按钮" BorderThickness="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Height="30" Background="#FF0123FF" FontWeight="Bold" FontSize="20" Foreground="White" Cursor="Hand">
  122. <Button.Template>
  123. <ControlTemplate TargetType="Button">
  124. <Border CornerRadius="5" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
  125. <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
  126. </Border>
  127. </ControlTemplate>
  128. </Button.Template>
  129. </Button>
  130. </StackPanel>
  131. </Grid>
  132. </Grid>
  133. </Window>