I am writing an app for Windows 8.1 that has a feature that displays a horizontal series of images that are contained within a wrapper class that I have extended from a previous API that I wrote.
Basically the set up is as follows:
I have base class A that exists within an external library that I am referencing.
I then have class B inside of my current project that extends A but add a WriteableBitmap
property:
public class B:A
{
private WriteableBitmap imageBitmap;
public WriteableBitmap ImageBitmap
{
get { return this.imageBitmap; }
set
{
if (Equals(value, imageBitmap)) return;
this.imageBitmap = value;
OnPropertyChanged();
}
}
}
I am then trying to display the images using a ItemsControl
in Xaml
with its ItemSource
bound to a "ImageList" which is a list of my wrapper class (which in the XAML file is apparently being linked only to class A
).
<ItemsControl ItemsSource="{Binding ImageList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source = "{Binding **trying to bind to the ImageBitmap property**}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
As you can see above, when I am trying to bind the Image
, the only properties I have access to are the ones originally declared in the base class A
. If I try to cast the binding somehow to to the newer subclass B
like this:
<Image Source = "{Binding (ex:B.ImageBitmap)}"/>
That throws errors saying its an invalid binding.
For reference, ex
is the name I gave for the namespace where B
exists in the project at he beginning of the Xaml
file.
Basically I am trying to figure out the proper way to cast a binding to a particular type that you have declared inside of the current project that extends a class that exists in an outside library that you are also referencing.
Any ideas?
Edit: To provide more detail as to what I am trying to do exactly, let me explain a little more and try to trim down the unnecessary details.
I have an external assembly, we will call it ExternalLib
. Inside ExternalLib
are the following classes:
A
which you saw above, which has various properties already declared in the external library.Another wrapper class called ImagePackage
which contains the following property(s):
List<A> ImageList;
String PackageName;
Then in my current project I have class B
which extends A
and adds an additional WriteableBitmap
property.
This all comes together in my app where I am trying to use nested ItemsControl
to display a vertical list of ImagePackage
, showing its PackageName
as the header. Inside each vertical list is then a horizontal list that displays each image inside that list (which is obtained from the WriteableBitmap
declared in B
). To imagine this, think if how Netflix is laid out (vertical and horizontal lists together).
To accomplish this, I have a global data context that I use and I have the following Xaml
:
<ItemsControl x:Name="ImageRoot" Height="861" Width="656" DataContext="{StaticResource GlobalDataContext}" ItemsSource="{Binding MainImageInfo.ImagePackages}" DisplayMemberPath="PackageName">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding ImageList}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source = "{Binding ImageBitmap}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Trying to declare the source of the Image
as ImageBitmap
causes Intellisense to throw a fit, but it still compiles and runs. The issue is that when the binding actually tries to update the entire app crashes (even though I have it set to break on exceptions) saying:
MyAppName has exited with code -1073741189 (0xc000027b).
Finally, the actual warning that Intellisense is providing on that line is:
Cannot resolve property "ImageBitmap" in data context of type "ExternalLib.A"
User contributions licensed under CC BY-SA 3.0