I have some interface and class that contain List
public interface IListContain
{
Int32 ItemCount
{
get;
}
}
public class myStackPanel : StackPanel, IListContain
{
... // implimentation ...
}
I want to do binding between some TextBlock and the variable that ‘point’ on the object instance myStackPanel – so i wrote is in this way
XAML:
<TextBlock x:Name="ItemCount" FontSize="12" Text="{Binding ElementName=ListContainObject, Path=ItemCount,Converter={StaticResource IntConverter}}" />
The convert code ( int to string )
public class IntToStringConverter : IValueConverter
{
public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
{
return ( ( int )value ).ToString();
}
public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture )
{
int result;
var succes = int.TryParse( ( string )value, out result );
return succes ? result : 0;
}
}
And on the cs file of the xaml i define in the constructor the
DataContext = this;
But still – nothing work !!!
I dont have fire convert event !!!
And i dont know what i did wrong.
Please help …
Thanks.
( this code is in silverlight and the ListContainObject is not null … its point on real object )
Can’t say for sure without you showing us your implementation, but it’s likely you’ve not used a dependency property for
ItemCount/ implementedINotifyPropertyChanged. Thus, WPF has no idea when the property is changing and the UI won’t update accordingly (nor will your redundant converter).