У меня есть ControlElement
, называемый MultiImageDevice
, который является элементом, который должен быть инициализирован списком / массивом URI для изображений, через которые я хочу переключаться.
XAML-код для MultiImageDevice:
<component:AbstractDevice x:Class="View.MultiImageDevice"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:component="clr-namespace:View"
x:Name="userControl"
d:DesignHeight="100" d:DesignWidth="100">
<Canvas Initialized="Level1Canvas_Initialized" Height="{Binding ElementName=userControl, Path=ActualHeight}" Width="{Binding ElementName=userControl, Path=ActualWidth}">
<Canvas Initialized="Level2FrameworkElement_Initialized">
<Image x:Name="image" Source="{Binding Path=ImageSources[0], RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type component:MultiImageDevice}}}" Height="{Binding ElementName=userControl, Path=ActualHeight}" Width="{Binding ElementName=userControl, Path=ActualWidth}">
<Image.Effect>
<DropShadowEffect BlurRadius="10" Opacity="0.5" ShadowDepth="3"/>
</Image.Effect>
</Image>
</Canvas>
</Canvas>
</component:AbstractDevice>
и код C # (без использования директив):
namespace View
{
public partial class MultiImageDevice : AbstractDevice
{
private double _currentImage = 1d;
internal string[] ImageURIs { get; set; }
public MultiImageDevice()
{
InitializeComponent();
}
public override void PositionChangedSignal(ComponentIdentifier identifier, double position)
{
if (_currentImage != position)
{
_currentImage = position;
//Switching shall occur here
}
}
}
}
И последний, но не менее важный звонок в отдельном XAML:
<component:MultiImageDevice Height="60" Canvas.Left="56.104" Canvas.Top="409.859" Width="60">
<component:MultiImageDevice.ImageURIs>
<x:Array Type="sys:String">
<sys:String>
pack://application:,,/img/AuxReleaseCancelButton_pushed.png
</sys:String>
</x:Array>
</component:MultiImageDevice.ImageURIs>
</component:MultiImageDevice>
Проблема с этим подходом - ошибка компилятора, утверждающая, что я не могу добавить ArrayExtension-Type
к String[]-Type
. Я также попытался оставить <x:Array>-part
или объявить массив как Resource
в MultiImageDevice
, что вызвало новые проблемы. Так что я сейчас в растерянности. Буду благодарен за любое предложение.
Спасибо