- 浏览: 399700 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
it is sometime useful to use a imgae as the content of the Button, a picture has more meaning than the humdrum buttons.
Below shows how you can make such a button.
You first define a button style. (where you can find such a button style from say Infragistics .xaml files)
<Style TargetType="Button" x:Key="ExpanderStyle"> <Setter Property="SnapsToDevicePixels" Value="true"/> <Setter Property="OverridesDefaultStyle" Value="true"/> <Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border x:Name="Border" DataContext="{x:Null}" Background="Transparent"> <ContentPresenter Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True"/> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style>
then you can create such a button, settings its content property through the use of Button.Content.
<Button x:Name="templatedButton" Style="{StaticResource ExpanderStyle}" Padding="{Binding ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}, Converter={StaticResource RowStateDisplayElementHeightConverter}, ConverterParameter=-0.45}" Height="{Binding ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}, Converter={StaticResource RowStateDisplayElementHeightConverter}, ConverterParameter=0.85}" Width="{Binding ActualHeight, RelativeSource={RelativeSource Mode=Self}}"> <Button.Visibility> <!-- <MultiBinding Converter="{StaticResource RowStateDisplayElementVisibilityConverter}"> <Binding Path="AutoIndentRows" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type local:GridControl}}" /> <Binding /> </MultiBinding> --> </Button.Visibility> <Button.Content> <Image IsHitTestVisible="False" SnapsToDevicePixels="True" Source="{Binding State, Converter={StaticResource RowStateDisplayValueConverter}}"> </Image> </Button.Content> <Button.InputBindings> <MouseBinding Gesture="LeftClick" Command="{Binding DataContext.ExpandCollapseCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding}"/> <MouseBinding Gesture="Shift+LeftClick" Command="{Binding DataContext.ExpandCollapseAllCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding}"/> <KeyBinding Gesture="Space" Command="{Binding DataContext.ExpandCollapseCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding}"/> <KeyBinding Gesture="Shift+Space" Command="{Binding DataContext.ExpandCollapseAllCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding}"/> </Button.InputBindings> </Button>
and last, you may use the following to convert a image (bitMap) to some BitmapImage (BitmapImage)
internal class RowStateDisplayValueConverter: IValueConverter { private static BitmapImage Collapse; private static BitmapImage Expanded; static RowStateDisplayValueConverter() { Collapse = GetBitmapImage(Properties.Resources.Collapse); Expanded = GetBitmapImage(Properties.Resources.Expanded); } static BitmapImage GetBitmapImage(System.Drawing.Bitmap bitmap) { using (var stream = new MemoryStream()) { bitmap.Save(stream, ImageFormat.Png); stream.Seek(0, SeekOrigin.Begin); var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = stream; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); return bitmapImage; } } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { switch ((RowState) value) { case RowState.Collapsed: return Collapse; case RowState.Expanded: return Expanded; default: case RowState.Leaf: case RowState.Hidden: return null; } } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotSupportedException(); } }
In the above, the image of is stored as some resources in the .xaml file.
发表评论
-
wpf - example to enhance ComboBox for AutoComplete
2014-09-19 15:56 1976first let’s see an example ... -
WPF – Virtualization – VirutalizationStackPanel and ItemsPanelTemplate
2013-08-05 21:55 1410Topic: WPF – Virtualization – ... -
wpf - BehaviorBase and one use examples
2013-06-18 18:41 1311Behavior is something that we ... -
WPF - Setting foreground color of Entire window
2013-06-13 16:00 1918You might as well as I would s ... -
WPF - Enhanced TabControl - TabControlEx aka Prerendering TabControl
2013-06-13 13:12 5330As an opening word, let's che ... -
wpf - ControlTemplate and AddLogicChild/RemoveLogicalChild
2013-06-10 15:42 1185Recently I was trying to debug ... -
wpf - default implicit style
2013-05-10 10:24 794We know that if you left out ... -
wpf - Style setter on the attached property
2013-05-08 14:54 2851I believe that you are familia ... -
wpf - specify enum values in xaml
2013-05-08 11:31 3585Many a situation you find tha ... -
wpf - IG xamDataGrid bind to XmlDataProvider with Xml Island
2012-12-18 14:28 1286Sometimes you may bind to some ... -
wpf - translate winform button/mouse event to wpf events
2012-12-12 17:37 2162It is common that we sometimes ... -
wpf - Freezable and its meaning
2012-09-27 12:38 0This article is based on the di ... -
wpf - Customize the grid lines for original wpf Grid control
2012-09-27 12:01 1458The System.WIndows.Controls.Gri ... -
c# - Convert from System.Drawing.Image to System.WIndows.Media.ImageSource
2012-09-25 14:27 7417In Previous discussion, we have ... -
wpf - Get Effective DependencyProperty value on a DependencyObject
2012-08-28 19:05 1044As discussed in my previous pos ... -
wpf - Default(Theme) style and its DefaultStyleKey
2012-08-28 17:54 1387As dicsused in the subsection o ... -
wpf - Dependency Property Value Precedence
2012-08-28 18:56 882A dependency property to an Dep ... -
wpf - WPF TemplateBinding vs RelativeSource TemplatedParent
2012-08-28 14:20 3713This is a post that summarizes ... -
wpf - ICutomTypeDescriptor , PropertyDescriptor and its use in PropertyGrid
2012-08-28 14:04 3580The type ICustomTypeDe ... -
wpf - tips to convert UI controls in WPF/Silverlight/Winforms into a Bitmap
2012-08-27 17:44 975In previous discussion, we have ...
相关推荐
### C#绘制不规则Button详解 #### 一、引言 在GUI开发中,我们经常需要自定义控件的外观来提升用户体验。本篇文章将详细介绍如何利用C#结合`System.Drawing.Drawing2D`命名空间中的类和方法来实现不规则形状的...
以上就是关于"Button加载Image"的相关知识点,包括如何在Visual Studio 2010中设置静态和动态加载按钮图像,以及一些相关的UI设计和性能优化考虑。希望这些内容能对你在实际开发中实现类似功能有所帮助。
在C#编程中,Windows Presentation Foundation(WPF)是一个强大的框架,用于构建具有丰富图形效果和用户交互的应用程序。在WPF中,我们可以利用它的强大功能来实现按钮的凸显凹陷效果,使得用户界面(UI)更加生动...
本教程将基于给定的"C#自定义漂亮按钮"主题,深入讲解如何利用C#和Visual Studio 2010创建一个自定义的按钮控件。我们将主要探讨以下几个方面: 1. **自定义控件基础**: 在.NET Framework中,自定义控件是通过...
在CAD(计算机辅助设计)应用开发中,C#是一种常用的语言,用于构建用户界面和交互功能。本主题将深入探讨如何使用C#来创建带有图标的Ribbon菜单,这是一种现代化的用户界面元素,常见于Microsoft Office等应用中。...
- **第七讲、Visual C#中的图形编程及Image类和Regions、Paths等** - **图形编程概述:** - 使用C#进行图形编程的基本概念和技术。 - **Image类的使用:** - Image类用于处理图像文件,包括加载、显示和保存图像...
- 对于控件如按钮或菜单项,可以通过`Button.Image`或`ToolStripMenuItem.Image`属性设置图标。 3. 图标的设计原则: - 清晰易识:图标应简洁明了,一眼就能辨认出其含义。 - 一致性:应用中的所有图标应保持...
**Visual Studio 2005 和 C#:构建连连看游戏** Visual Studio 2005 是微软推出的一款强大的集成开发环境(IDE),主要用于编写 .NET Framework 应用程序。这款 IDE 支持多种编程语言,包括 C#,C++,VB.NET 等。在...
在C#中生成二维码是一项常见的任务,特别是在移动应用、网页或物联网(IoT)场景中。本实例将向您展示如何使用ZXing.Net库来实现这个功能。ZXing.Net库是一个开源项目,提供了多种条码和二维码的读取与生成。 首先,...
《Windows Forms Programming with C#》是一本专注于使用C#进行Windows桌面应用开发的专业书籍,它提供了丰富的源代码供读者学习和实践。Windows Forms是.NET Framework中的一个关键组件,用于构建功能丰富的、用户...
在WinForms中,可以使用Visual Designer创建和布局控件,如TextBox、Button和DataGridView,以及调整它们的属性和事件。 7. 事务处理:对于涉及多条数据库操作的业务逻辑,我们可以使用SqlTransaction来确保数据的...
在IT行业中,Visual C#是一种广泛使用的编程语言,尤其在Windows平台上的应用程序开发中占据了重要地位。本实例聚焦于Visual C#在图像处理程序设计方面的应用,这涉及到大量的图形用户界面(GUI)设计、图像处理算法...
- 可以通过`IDI_ICON1`, `IDI_ICON2`等预定义ID,或者自定义ID如`IDB_IMAGE1`, `IDB_IMAGE2`。 4. **切换图片的逻辑**: - 在`OnBnClickedButton1()`函数中,获取图片控件的句柄,然后根据当前显示的图片ID来判断...
在提供的文件内容中,包含了关于C#实验指导书的详细知识点,以及创建简单的.NET...通过实验步骤的详细指导,学习者能够逐步掌握使用Visual Studio开发环境进行C#编程的完整流程,从而加深对.NET应用程序开发的理解。
在本文中,我们将深入探讨如何使用Visual Studio 2008和C#语言来编写一个基本的抓图程序。Visual Studio 2008是一款强大的集成开发环境(IDE),支持多种编程语言,包括C#,它为开发人员提供了丰富的工具和功能,...
Image image = sender as Image; if (image != null) { // 获取鼠标点击时相对于图像左上角的坐标 Point mousePoint = e.GetPosition(image); // 记录当前的偏移量 _offset = new Point(image.Margin.Left - ...
2. **安装 Visual Studio 2010**:安装 Visual Studio 2010,并确保安装了 C# 开发环境。 3. **准备测试图片**:准备好一张用于测试的图片文件。 #### 三、编写 Halcon 代码 1. **打开 Halcon 开发环境**:启动 ...
本篇文章将深入探讨如何使用C#来开发一个名为“Choose The Flag”(选择国旗)的窗体应用程序。这个小游戏旨在测试用户对世界各国国旗的识别能力,同时也为初学者提供了一个实践C#编程和Windows Forms应用开发的实例...
button.Image = buttonIcon; } ``` 此外,还可以使用Visual Studio的设计器来直观地为控件分配图标。只需打开窗体设计器,选择控件,然后在属性窗口中找到Image属性,点击右侧的省略号按钮,从资源管理器中选择...
《Visual C# 案例开发集锦15》是一个专为C#初学者准备的资源包,其中包含了丰富的案例代码,旨在帮助学习者更好地理解和掌握C#编程语言。在这个集合中,我们可以看到一个名为“案例5:抓图软件的实现”的项目,这将...