2024年终活动

DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

如何放大DevExpress DXGrid for WPF单元格中的图像?

来源:本站原创   发布时间:2012-09-04   浏览:2910次

在窗口中创建一个标准图像控件,并且当用户点击图像时,你还可以隐藏或者显示该控件。网格单元格中的图像应该被绑定在按钮中。这样,你就可以轻松处理Click事件了。

VB.NET

<Window Height="598"
Title="Window1"
Width="811"
x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:local="clr-namespace:WpfApplication1"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Grid>
<dxg:GridControl Name="gridControl1">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="CategoryID" />
<dxg:GridColumn FieldName="CategoryName" />
<dxg:GridColumn FieldName="Picture" AllowColumnFiltering="False">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<Button Command="{x:Static local:Window1.ShowImage}">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter />
</ControlTemplate>
</Button.Template>

<Image Source="{Binding Path=RowData.Row[Picture]}" HorizontalAlignment="Left" Stretch="None" />
</Button>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
</dxg:GridControl.Columns>

<dxg:GridControl.View>
<dxg:TableView x:Name="view" AutoWidth="True" />
</dxg:GridControl.View>
</dxg:GridControl>

<Image Source="{Binding}" Name="image" Visibility="Hidden" MouseLeave="image_MouseLeave" Margin="30,30,50,12" />
</Grid>

</Window>

C#

<Window Height="598"
Title="Window1"
Width="811"
x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:local="clr-namespace:WpfApplication1"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Grid>
<dxg:GridControl Name="gridControl1">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="CategoryID" />
<dxg:GridColumn FieldName="CategoryName" />
<dxg:GridColumn FieldName="Picture" AllowColumnFiltering="False">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<Button Command="{x:Static local:Window1.ShowImage}">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter />
</ControlTemplate>
</Button.Template>

<Image Source="{Binding Path=RowData.Row[Picture]}" HorizontalAlignment="Left" Stretch="None" />
</Button>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
</dxg:GridControl.Columns>

<dxg:GridControl.View>
<dxg:TableView x:Name="view" AutoWidth="True" />
</dxg:GridControl.View>
</dxg:GridControl>

<Image Source="{Binding}" Name="image" Visibility="Hidden" MouseLeave="image_MouseLeave" Margin="30,30,50,12" />
</Grid>

</Window>

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/321.html
扫码咨询
电话咨询
023-68661681
返回
顶部