c# - 如何从图像获取绑定在源上的图像路径
问题描述
Hi everyone.
我需要从绑定在 Image 上的 Source 获取 Text 并创建一个返回字符串的 Class 以使用此值在 xaml 上加载图像。
出色地...
- 我有一个用户控件:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:cal="http://www.caliburnproject.org"
xmlns:Ihor="clr-namespace:ConsoleApp1;assembly=WpfApp14"
mc:Ignorable="d"
- 我有一个带有 ConsoleApp1 命名空间的 WpfApp14.dll
xmlns:Ihor="clr-namespace:ConsoleApp1;assembly=WpfApp14"
- 在画布中,我得到了图像:
<Canvas Name="Canvas">
.
.
.
<Image x:Name="MoveImageFront" Grid.Column="1" Grid.Row="1" Source="{Binding Path=ActiveGame.FrontImagePath}" Opacity="100" >
.
.
.
</Canvas>
</UserControl>
- 我需要一个读取
Source="{Binding Path=ActiveGame.FrontImagePath}"
获取高度和宽度并返回图像方向的类,就像这样(只是一个例子):
[我想在 ConsoleApp1 命名空间下将这个类添加到我的 WpfApp14.dll]
public static string ImgOrientation(Bitmap imagefront)
{
string Orientationimg;
if (imagefront.Width = 0)
Orientationimg = ("Portrait");
return Orientationimg;
else
if (imagefront.Width >= imagefront.Height)
Orientationimg = ("Landscape");
else Orientationimg = ("Portrait");
return Orientacionimg;
}
- 然后在 XAML 中,如果返回是纵向,我想显示一个名为 portrait.png 的图像,如果返回是横向,我想显示一个名为 landscape.png 的图像。
提前致谢!
解决方案
推荐阅读
- asp.net-mvc - 如何创建具有多个表的登录表单?
- c++ - 枚举的 std::unordered_set,调用 find 给出分段错误
- c# - C# 强类型属性
- javascript - 为什么地图未定义?
- javascript - 角度选择选项
- c# - 如何使用 NPOI 清除 C# 中的单元格值
- powershell - 将 C++ 转换为 PowerShell
- sql - CTE:每 15 天循环输入数据| SQL、SQL 服务器
- f# - async { ... AsyncAdd ... } 和 async { ... do AsyncAdd ... } 有什么不同?
- input - IONIC 4 Setting 可输入的最大值