WPF 中的相关样式
<Image Name="icon" Width="40" Height="40" Source="/Resources/huocheS.png" />
<Border Width="210" BorderBrush="#626363" BorderThickness="1" Margin="5">
<Label x:Name="lab" Foreground="#626363" >sdf</Label>
</Border>
<StackPanel Height="230" x:Name="pinfo" >
<StackPanel.Background>
<ImageBrush ImageSource="/Resources/info.png" Opacity="0.7"></ImageBrush>
</StackPanel.Background>
</StackPanel>
Label 设置背景色
Label.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#626363")); Label.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#626363"));
设置背景图片
//tabA1.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri(filepath)) };
画图形顺序为逆时针
<Polygon x:Name="pl1" Points="0,0 0,30 160,30 130,0" Stroke="Purple" StrokeThickness="0"> <Polygon.Fill> <SolidColorBrush Color="#126CB1"/> </Polygon.Fill> </Polygon>
后台修改所画的图形位置
private void Removestate(Polygon path, TextBlock label) { if (path.Points[0].Y == 0) { path.Points[0] = new Point(path.Points[0].X + 10, path.Points[0].Y + 10); path.Points[1] = new Point(path.Points[1].X + 10, path.Points[1].Y + 10); path.Points[2] = new Point(path.Points[2].X + 10, path.Points[2].Y + 10); path.Points[3] = new Point(path.Points[3].X + 10, path.Points[3].Y + 10); Canvas.SetTop(label, Canvas.GetTop(label) + 10); Canvas.SetLeft(label, Canvas.GetLeft(label) + 10); path.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#547EAD")); } }
Image 绑定
image1.Source = new BitmapImage(new Uri(filepath + "Resources\\images\\map2.png"));
RichTextBox定时刷新添加内容
delegate void mydelete(); private void bindRichText() { try { DispatcherTimer dTimer = new System.Windows.Threading.DispatcherTimer(); dTimer.Tick += new EventHandler(dTimer_Tick); dTimer.Interval = new TimeSpan(0, 0, 0, 0, 1000); string filepath = Environment.CurrentDirectory; if (filepath.Substring(filepath.Length - 1) != "/") filepath += "\\" + "DataFile\\" + "rich1.txt"; StreamReader sr = new StreamReader(filepath, Encoding.Default); allinfo = new List<string>(); string rowinfo = ""; while (!string.IsNullOrEmpty(rowinfo = sr.ReadLine())) { allinfo.Add(rowinfo); } sr.Close(); sr.Dispose(); setText(); dTimer.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } void dTimer_Tick(object sender, EventArgs e) { try { mydelete dele = new mydelete(setText); dele.Invoke(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void setText() { if (i == allinfo.Count - 1) i = 0; this.richTextmain.AppendText(allinfo[i] + "\r"); this.richTextMemo.ScrollToEnd(); i++; }
Frame 绑定
string filepath = Environment.CurrentDirectory; if (filepath.Substring(filepath.Length - 1) != "/") filepath += "\\" + "MyHtml\\sdf.htm"; frame.Source = new Uri(filepath);
后台画路径/图形
void dTimer1_Tick(object sender, EventArgs e) { Random dr = new Random(); string varchar = chartData[dr.Next(0, chartData.Length)]; Thread.Sleep(1000); if (varchar != null && varchar != "") { string[] v = varchar.Split(','); Point p1 = new Point(Convert.ToInt32(v[0]), Convert.ToInt32(v[1])); Point p2 = new Point(Convert.ToInt32(v[2]), Convert.ToInt32(v[3])); Point p3 = new Point(Convert.ToInt32(v[4]), Convert.ToInt32(v[5])); Point p4 = new Point(Convert.ToInt32(v[6]), Convert.ToInt32(v[7])); Point[] values = new Point[] { p1, p2, p3, p4 }; StreamGeometry theGeometry = BuildRegularPolygon(values, true, true); path1.Data = theGeometry; } }
WPF DataGrid
<UserControl.Resources> <!--DataGridRow--> <Style TargetType="{x:Type DataGridRow}"> <Setter Property="IsTabStop" Value="False" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DataGridRow}"> <Grid Name="Root"> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Rectangle x:Name="InvalidVisualElement" Grid.RowSpan="2" Grid.ColumnSpan="2" Opacity="0.2" Fill="#87CFFF" /> <DataGridCellsPresenter Grid.Column="1" TextBlock.Foreground="Black" Name="CellsPresenter" /> <Rectangle Grid.Row="2" Grid.Column="1" Fill="Transparent" Name="BottomGridLine" HorizontalAlignment="Stretch" Height="1" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="Fill" TargetName="InvalidVisualElement" Value="#FF9900" /> <Setter Property="Opacity" Value="0.8" TargetName="InvalidVisualElement" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type DataGridColumnHeader}"> <Setter Property="Foreground" Value="White" /> <Setter Property="Background" Value="#87CFFF" /> <Setter Property="IsTabStop" Value="False" /> <Setter Property="SeparatorBrush" Value="Black" /> <Setter Property="Height" Value="Auto" /> <Setter Property="MinHeight" Value="30" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DataGridColumnHeader}"> <Grid Name="Root"> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Rectangle x:Name="BackgroundRectangle" Stretch="Fill" Fill="#87CFFF" Opacity="0.5" Grid.ColumnSpan="2" /> <Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}"> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Left" Margin="6,0,0,0" TextBlock.FontFamily="Segoe UI" TextBlock.FontSize="14" TextBlock.FontWeight="Regular" Content="{TemplateBinding Content}" /> <!--<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Margin="6,0,0,0" TextBlock.FontFamily="Segoe UI" TextBlock.FontSize="14" TextBlock.FontWeight="Regular" Text="{Binding RelativeSource={RelativeSource AncestorType=DataGridCell},Path=Content}" />--> <Path Grid.Column="1" Name="SortIcon" Fill="#87CFFF" RenderTransformOrigin=".5,.5" HorizontalAlignment="Left" VerticalAlignment="Center" Opacity="0" Stretch="Uniform" Width="8" Margin="4,0,0,0" Data="F1 M -5.215,6.099L 5.215,6.099L 0,0L -5.215,6.099 Z "> <Path.RenderTransform> <ScaleTransform ScaleX=".9" ScaleY=".9" /> </Path.RenderTransform> </Path> </Grid> <Rectangle Name="VerticalSeparator" Grid.Column="1" Width="1" VerticalAlignment="Stretch" Fill="{TemplateBinding SeparatorBrush}" Visibility="{TemplateBinding SeparatorVisibility}" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <!--DataGridCell--> <Style TargetType="{x:Type DataGridCell}"> <Setter Property="Background" Value="Transparent" /> <Setter Property="MinHeight" Value="30" /> <Setter Property="Height" Value="Auto" /> <Setter Property="IsTabStop" Value="False" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DataGridCell}"> <Grid Name="Root" Background="{TemplateBinding Background}"> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <ContentPresenter Content="{TemplateBinding Content}" TextBlock.FontFamily="Segoe UI" TextBlock.TextAlignment="Justify" TextBlock.FontSize="14" TextBlock.FontWeight="Regular" ContentTemplate="{TemplateBinding ContentTemplate}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="6,0,0,0" /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type Hyperlink}"> <Setter Property="Foreground" Value="Black" /> <Setter Property="Cursor" Value="Hand" /> </Style> </UserControl.Resources> <DataGrid Margin="10,10,5,0" Grid.Row="1" Grid.Column="0" Width="550" Canvas.Right="1" CanUserAddRows="False" Name="grid1" Foreground="Black" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden" Background="Transparent" > <DataGrid.Columns> <DataGridTemplateColumn Width="150"> <DataGridTemplateColumn.Header> <TextBlock VerticalAlignment="Center" Foreground="White" Padding="5,5,5,5" TextWrapping="Wrap" TextTrimming="WordEllipsis" >kk</TextBlock> </DataGridTemplateColumn.Header> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Path=kk}" VerticalAlignment="Center" Foreground="White" Padding="5,5,5,5" TextWrapping="Wrap" TextTrimming="WordEllipsis" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn Width="120"> <DataGridTemplateColumn.Header> <TextBlock VerticalAlignment="Center" Foreground="White" Padding="5,5,5,5" TextWrapping="Wrap" TextTrimming="uu" >Change Location</TextBlock> </DataGridTemplateColumn.Header> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Path=uu}" VerticalAlignment="Center" Foreground="White" Padding="5,5,5,5" TextWrapping="Wrap" TextTrimming="WordEllipsis" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTextColumn Header="ss" Width="120" Foreground="White" Binding="{Binding ss}" /> <DataGridTextColumn Header="dd" Width="60" Foreground="White" Binding="{Binding dd}" /> </DataGrid.Columns> </DataGrid> private void BindingTxt1() { ObservableCollection<ItemA21> Datalist = new ObservableCollection<ItemA21>(); string filename = "A21_new.txt"; int columns = 5; int rows = 3; try { string filepath = Environment.CurrentDirectory; if (filepath.Substring(filepath.Length - 1) != "/") filepath += "\\" + "DataFile\\" + filename; StreamReader sr = new StreamReader(filepath, Encoding.Default); string txtinfo = sr.ReadToEnd(); string[] strRows = txtinfo.Split(';'); int Total = strRows.Length; Random ra = new Random(); int Filtered = 13; for (int i = 0; i < Total; i++) { int j = ra.Next(1, Total); ItemA21 item = new ItemA21(); string[] strColumns = strRows[i].Split(','); if (strColumns.Length == columns) { string str0 = strColumns[0]; if (str0.IndexOf(":") > 0) item.ss= str0.Substring(str0.IndexOf(":") + 1); string str1 = strColumns[1]; if (str1.IndexOf(":") > 0) item.tt= str1.Substring(str1.IndexOf(":") + 1); string str2 = strColumns[2]; if (str2.IndexOf(":") > 0) item.dd= str2.Substring(str2.IndexOf(":") + 1); string str3 = strColumns[3]; if (str3.IndexOf(":") > 0) item.kk= str3.Substring(str3.IndexOf(":") + 1); string str4 = strColumns[4]; if (str4.IndexOf(":") > 0) item.uu= str4.Substring(str4.IndexOf(":") + 1); Datalist.Add(item); } else { //i--; } } //for (int j = 0; j < rows - strRows.Length; j++) //{ // ItemA21 item = new ItemA21(); // Datalist.Add(item); //} grid1.ItemsSource = Datalist; sr.Close(); sr.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }