WPF 自带控件 总结之二
2012-03-12 14:09
281 查看
=============================================
ContextMenu
==============================================
TreeView 绑定
==================================================
ToolBar
==================================================
Status Bar
===================================================
PrograssBar
=====================================================
slider
=====================================================
InkCanvas
ContextMenu
<ListBox> <ListBox.ContextMenu> <ContextMenu> <MenuItem Header="hello" ></MenuItem> <MenuItem Header="click me" ></MenuItem> <MenuItem Header="abort me" ></MenuItem> </ContextMenu> </ListBox.ContextMenu> <ListBoxItem>aaa</ListBoxItem> <ListBoxItem>bbb</ListBoxItem> <ListBoxItem>ccc</ListBoxItem> </ListBox>
==============================================
TreeView 绑定
<Grid> <Grid.Resources> <HierarchicalDataTemplate DataType="{x:Type src:LeafNode}" ItemsSource="{Binding Path=Children}"> <TextBlock Text="{Binding Path=Data}" ToolTip="{Binding Path=Data}"></TextBlock> </HierarchicalDataTemplate> </Grid.Resources> <TreeView x:Name="twLeaf"> </TreeView> </Grid> private void InitTree() { ////init 5 root nodes List<LeafNode> roots = new List<LeafNode>(); for (int i = 0; i < 5; i++) { LeafNode child = new LeafNode() { Data = "root" + i.ToString() }; child.Children = new List<LeafNode>(); roots.Add(child); ////10 children for (int j = 0; j < 10; j++) { LeafNode subChild = new LeafNode() { Data = "son" + j.ToString() }; subChild.Children = new List<LeafNode>(); ////15 children child.Children.Add(subChild); for (int k = 0; k < 15; k++) { LeafNode gs = new LeafNode() { Data = "grantSon" + k.ToString() }; subChild.Children.Add(gs); } } } twLeaf.ItemsSource = roots; } public class LeafNode { public string Data { get; set; } public List<LeafNode> Children { get; set; } }
==================================================
ToolBar
<ToolBar> <Button Content="A" Height="24" Width="20"></Button> <Button Content="B" Height="24" Width="20"></Button> <Button Content="C" Height="24" Width="20"></Button> <Button Content="D" Height="24" Width="20"></Button> </ToolBar>
==================================================
Status Bar
<StatusBar> <Label Content="AAA"></Label> <Button Content="BBB"></Button> <TextBox Text="CCC"></TextBox> </StatusBar>
===================================================
PrograssBar
<ProgressBar x:Name="pgTest" Width="200" Height="24" IsIndeterminate="False"></ProgressBar> private void InitPrograssBar() { double max = pgTest.Maximum; ThreadPool.QueueUserWorkItem(new WaitCallback((o) => { int i = 0; while (i <= max) { Thread.Sleep(200); pgTest.Dispatcher.Invoke(new Action(() => { pgTest.Value = ++i; })); } })); }
=====================================================
slider
<StackPanel Orientation="Horizontal"> <Slider x:Name="slTest" Width="200" IsSelectionRangeEnabled="True" SelectionStart="20" SelectionEnd="60" ValueChanged="slTest_ValueChanged" Maximum="300" Minimum="0"></Slider> <Label x:Name="lblSlider"></Label> <Button x:Name="btnSliderValue" Width="50" Height="24" Content="Val" Click="btnSliderValue_Click"></Button> </StackPanel> private void btnSliderValue_Click(object sender, RoutedEventArgs e) { MessageBox.Show(slTest.Value.ToString()); } private void slTest_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { lblSlider.Content = slTest.Value.ToString(); }
=====================================================
InkCanvas
<StackPanel> <InkCanvas Margin="10 0" Background="White" Width="500" Height="100" x:Name="cvs"> </InkCanvas> <Button x:Name="saveCvs" Content="Save" Width="50" Height="24" Click="saveCvs_Click"></Button> </StackPanel> private void saveCvs_Click(object sender, RoutedEventArgs e) { string fileN = "D:/1.png"; if (File.Exists(fileN)) { File.Delete(fileN); } // string sigPath = System.IO.Path.GetTempFileName(); MemoryStream ms = new MemoryStream(); FileStream fs = new FileStream(fileN, FileMode.Create); RenderTargetBitmap rtb = new RenderTargetBitmap((int)cvs.Width, (int)cvs.Height, 0, 0, PixelFormats.Default); rtb.Render(this.cvs); BmpBitmapEncoder encoder = new BmpBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(rtb)); encoder.Save(fs); fs.Close(); }
相关文章推荐
- WPF 自带控件札记
- WPF学习总结和记录(三)Items控件上
- [WPF 知识总结系列] —— 基本控件的简单样式集合
- WPF学习总结和记录(四)Items控件下
- 农国苏:WPF控件简单总结(完善中……)
- Windows Presentation Foundation(WPF)中的数据绑定(使用XmlDataProvider作控件绑定之二:使用外部URL的XML文件)
- 【Cocoa(mac) Application 开发系列之二】总结一些常用控件以及简单在自定义View上绘制字符串
- WPF 控件总结
- VS自带WPF,Silverlight控件样式和模板
- wpf 常用控件 总结之三
- WPF学习总结和记录(二)内容控件
- Android基础核心总结之二-----Spinner、AutoCompleteTextView(自动完成控件)
- WPF 自带控件札记
- wp8和wpf里监听控件自带属性的变化
- 九款WPF界面控件的优势总结
- WPF中控件进行伸缩移动旋转变换的经验总结
- WPF 几种常用控件样式的总结
- WPF 几种常用控件样式的总结
- 在MFC下调用WPF控件的总结
- WPF学习总结和记录(一)内容控件