我正在从特定表中的数据库中检索图像。它显示了该表中的所有图像。
现在我需要获取选定的图像名称,它使用绑定和工具提示显示名称,但是我需要在单击图像时获取,选定的图像名称应该在消息框中查看。
这是我的代码:
imageView.cs 页面。
var query1 = DB_Linq.tbl_ItemMaster.Select(cust => new { cust.Item_Code, cust.Item_Image,cust.ImagePath, cust.ItemName_EN }).ToList();
var QBM1 = (from po in DB_Linq.tbl_ItemMaster
where po.ActiveFlag == true
select new ImageEntity
{
ImagePath = po.ImagePath,
ItemName_EN = po.ItemName_EN
}
);
return QBM1.ToList<ImageEntity>();
图像实体.cs
class ImageEntity
{
public String ImagePath
{
get;
set;
}
public String ItemName_EN
{
get;
set;
}
}
Invoice.Xaml.cs-page
private void BindImages()
{
try
{
// Store Data in List Object
List<ImageEntity> ListImageObj = ImageView.GetAllImagesData();
// Check List Object Count
if (ListImageObj.Count > 0)
{
// Bind Data in List Box Control.
LsImageGallery.DataContext = ListImageObj;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
Xaml 代码是:
<Page.Resources>
<ItemsPanelTemplate x:Key="ListBox_HorizontalItems">
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
<DataTemplate x:Key="ImageGalleryDataTemplate" x:Name="ImageGalleryDataTemplate" >
<Grid>
<Border BorderBrush="ForestGreen" BorderThickness="3" Width="120" Height="120" Padding="10" Margin="15" CornerRadius="10">
<Image Source="{Binding ImagePath}" Stretch="Fill" HorizontalAlignment="Center" >
<Image.ToolTip>
<Grid>
<Image Source="{Binding ImagePath}" Stretch="Fill" HorizontalAlignment="Center" Height="100" Width="100"></Image>
</Grid>
</Image.ToolTip>
</Image>
</Border>
<Border>
<Grid>
<TextBlock Text="{Binding ItemName_EN}" ToolTip="{Binding ItemName_EN}" />
</Grid>
</Border>
<Grid x:Name="LayoutRoot" Background="DarkGreen" >
<Button Click="ButtonClicked" ToolTip="{Binding ItemName_EN}" >
<Image Source="{Binding ImagePath}" Stretch="Fill" Height="100" Width="100" HorizontalAlignment="Center"/>
</Button>
</Grid>
</Grid>
</DataTemplate>
<ItemsPanelTemplate x:Key="ImageGalleryItemsPanelTemplate">
<!--Display Images on UniformGrid Panel-->
<UniformGrid Columns="4" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
</ItemsPanelTemplate>
</Page.Resources>
<Grid>
<ListBox x:Name="LsImageGallery" ItemsSource="{Binding}" ItemTemplate="{DynamicResource ImageGalleryDataTemplate}" ItemsPanel="{DynamicResource ImageGalleryItemsPanelTemplate}">
<ListBox.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black"/>
<GradientStop Color="#FF1E2A2F" Offset="1"/>
</LinearGradientBrush>
</ListBox.Background>
</ListBox>
</Grid>
</Page>