Your Binding
is not being specified in the correct way.
In the way you are currently specifying the Binding
you are saying find a property called 80 (i.e. the Path
) on the object currently set/inherited via the DataContext
property and use its value.
(property names can't start with a digit and I think the quoted syntax to indicate the Path
may be wrong anyhow...thus the Binding
is wrong....and your converter doesn't get called).
To confirm this, you can look at the Output Window in Visual Studio while you're debugging the application...it should inform you about Bindings that have errors...see these links for details:
I believe your intention was to have a literal constant value which is passed to your converter in order to calculate a suitable value.
Instead of using a Converter
, you should look at doing it using a MarkupExtension
.....yes you could "fudge it" with a converter, by binding to an arbitrary object and just passing your 80 value as a ConverterParameter
....but that's not the best way and a big kludge.
Here are some links on writing a MarkupExtension:
...so create a MarkupExtension
derived class e.g. HeightAdjustedExtension : MarkupExtension .... implement the ProvideValue
method and "properties" on the extension that can funnel incoming data.
...then you could use it in this way ...
ItemHeight="{myns:HeightAdjusted 80}"
This is not tested, but something like this (gives you something to play around with):
public class HeightAdjustedExtension : MarkupExtension
{
[ConstructorArgument("height")]
public string Height { get; set; }
public HeightAdjustedExtension () { }
public HeightAdjustedExtension (string height)
{
Height = height;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
int theheight;
int.TryParse( Height, out theheight );
double ScreenHeight = (int)Window.Current.Bounds.Height;
double factor = 1050/(double)theheight ;
return (int)(ScreenHeight/factor);
}
}